如何使用TS CDK在AWS API网关上指定缓存键? 我正在使用AWS CDK管理我的AWS Instra,for TypeScript,特别是AWS-cdk-lib@2.182.0。 我的目标是启用API网关缓存以获取端点,例如获得subpath/{customerId}/使用Customeri ...

问题描述 投票:0回答:0
使用

customerId

作为缓存键这样的端点。有效地,在AWS控制台上,部署后应该看起来像这样:
,但这是我目前得到的:
enter image description here

这是我的API网关部署: enter image description heredeployOptions: { stageName: props.stageName, metricsEnabled: true, cachingEnabled: true, cacheClusterEnabled: true, cacheClusterSize: '0.5', cacheTtl: Duration.seconds(3600), cacheDataEncrypted: true, },

注:这是API网关V1

的REST API 和我的方法配置:

methods.addMethod('GET', new LambdaIntegration(lambda), {
      authorizer: requestAuthorizer,
      requestValidator: requestParamValidator,
      requestParameters: {
        'method.request.path.customerId': true,
      },
      methodResponses: [
        {
          statusCode: '200',
        },
        {
          statusCode: '404',
        },
        {
          statusCode: '401',
        },
      ],
    });

我尝试添加这样的参数:

cacheKeyParameters
或在我的内部

methods.addMethod('GET', new LambdaIntegration(lambda), { authorizer: requestAuthorizer, requestValidator: requestParamValidator, cacheKeyParameters: ['method.request.path.customerId'], requestParameters: { 'method.request.path.customerId': true, }, methodResponses: [ { statusCode: '200', }, { statusCode: '404', }, { statusCode: '401', }, ], });

中显示了我显示的
methodOptions

,但是我得到了这个编译错误:
deployOptions

即使我用 @ts-ignore忽略了这一点,它也行不通,结果仍然是:

我也尝试了:
Object literal may only specify known properties, and cacheKeyParameters does not exist in type MethodOptions
orenter image description here myMethod.addPropertyOverride('CacheKeyParameters', [ 'method.request.path.customerId', ]);

但是,部署失败了:

myMethod.addPropertyOverride('cacheKeyParameters', [
  'method.request.path.customerId',
]);

[#: extraneous key [CacheKeyParameters] is not permitted]


这很有意义,因为

CDK文档的方法是没有Cache-Keyparameters或任何与缓存相关的参数。但是,我该怎么做?
甚至没有Chatgpt O1可以帮助我解决这个XD

API Gateway的集成对象上存在cache键参数,而不是显示的方法对象
HEREY

typescript amazon-web-services caching aws-api-gateway aws-cdk
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.