问题描述
我们正在使用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
我们在这里想念什么?为什么事件有效载荷中会有不同的资源值?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)