我们正在使用sam local
在本地测试我们的API网关,为此,我们生成了template.yml文件并引用了所有必要的资源。 (例如Lamdalayers)。
现在我们面临的问题是,所有路径参数(例如{id}
)都无法在本地访问,因为路径参数值在环境中解析方式不同
类似的请求
GET /some-endpoint/12345-12345-12345-12345
导致以下资源值:
sam-local
"resource": "/{proxy+}"
api-gateway在线:
"resource": "/some-endpoint/{id}"
如果您想知道,我们在明确地创建此 LambdaRestApi -通过CDK的终结点
const api = new LambdaRestApi(this, apiName, {
handler: router,
proxy: false,
cloudWatchRole: true,
description: 'API',
deployOptions: {
stageName: 'prod',
loggingLevel: MethodLoggingLevel.INFO,
dataTraceEnabled: true,
},
minimumCompressionSize: 0,
domainName: domainProperties,
})
const versionRoot = api.root
versionRoot.addProxy({
anyMethod: true,
defaultIntegration: new LambdaIntegration(router),
})
const endpoint = versionRoot.addResource('some-endpoint')
recipes.addMethod(HttpMethod.GET)
const endpoint2 = endpoint.addResource('{id}')
endpoint2.addMethod(HttpMethod.GET)
我们通过以下方式启动服务:
sam local start-api --profile development --debug --region eu-central-1
我们在这里想念什么?为什么事件有效载荷中会有不同的资源值?