我的目标是,我试图编写一个(单一) SAM模板,以获得由Api事件触发的Lambda函数。
我希望有多个API阶段(比如"dev“、”the“、"prod"),我希望每个阶段都映射到同名的Lambda别名上。
我不希望在每个部署中生成一个新的lambda版本,我希望手动设置lambda版本供每个lambda别名使用。当然,"dev“别名的意思是指向$LATEST代码版本。
我尝试了什么,我得到了什么,
我修改了经典的"hello_world“模板,如下所示。现在,当第一次部署(比方说到"dev")时,一切似乎都像预期的那样正常工作。但是,如果我试图部署到“测试”阶段,那么这个新阶段的API就会响应,而"dev“的API就会停止响应。
我遗漏了什么?
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
zzzz
Sample SAM Template for zzzz
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Parameters:
StageAliasName:
Description: stage / alias name to be used in this deploy
Type: String
AllowedValues:
- prod
- stage
- dev
- v1
Default: dev
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref StageAliasName
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
AutoPublishAlias: !Ref StageAliasName
FunctionName: zzz
Environment:
Variables:
stage: !Ref StageAliasName
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref ApiGatewayApi
Path: /hello
Method: GET
# Auth:
# ApiKeyRequired: true
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
# HelloWorldApi:
# Description: "API Gateway endpoint URL for Prod stage for Hello World function"
# Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn发布于 2021-01-21 21:59:34
我和你有同样的问题,发现了这个问题:https://jun711.github.io/aws/deploy-api-gateway-to-multiple-stage-when-aws-sam-replaces-previous-stages/。看起来SAM取代了以前的阶段。
这个六月的家伙做了一些手动的步骤,使它工作。知道它能工作是很好的,但是我想我要用ansible来为不同的环境模板出不同版本的模板,然后再运行它。
https://stackoverflow.com/questions/65724680
复制相似问题