【发布时间】:2019-12-09 21:02:30
【问题描述】:
我的应用程序有一个 SAM 模板。每次我使用新的 API Gateway 阶段名称部署 SAM 模板时,它都会替换之前创建的阶段。
所以,发现这篇文章可以帮助我发布指向不同 lambda 版本的不同版本。 https://aws.amazon.com/blogs/compute/using-api-gateway-stage-variables-to-manage-lambda-functions/
但是,为此,我必须在部署后手动更改 API 网关。 那么,有什么方法可以使用 AWS SAM 做到这一点?
例如,考虑以下 CloudFormation 模板提取:
ProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: ANY
RestApiId: !Ref Api # AWS::ApiGateway::RestApi defined elsewhere
ResourceId: !Ref ProxyResource # AWS::ApiGateway::Resource defined elsewhere
AuthorizationType: NONE #auth is done at the public API layer
Integration:
# client request passed through as-is. "Lambda proxy integration"
Type: AWS_PROXY
Uri: !Join
- ''
- - 'arn:aws:apigateway:'
- !Sub ${AWS::Region}
- ':lambda:path/2015-03-31/functions/${!stageVariables.FunctionArn}/invocations'
IntegrationHttpMethod: ANY
PassthroughBehavior: WHEN_NO_MATCH
这应该允许我使用在运行时确定的 Lambda 函数创建一个方法,就像在 example 中一样。但是,当我这样做时,在部署模板时出现以下错误:
ProxyMethod CREATE_FAILED Invalid lambda function (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; ....
我如何通过 CloudFormation 定义目标 Lambda 函数由阶段变量确定的 API 网关方法?
【问题讨论】:
-
请将您的模板代码添加到您的问题中。
标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway aws-sam