[英]How do you shift/escalate your AWS lambda from one envr to another (eg. dev to prod) using alias?
I am creating a AWS serverless application with SAM.我正在使用 SAM 创建一个 AWS 无服务器应用程序。 Basically what I would like to achieve is to use API Gateway's different stages (dev/test/prod) to invoke various Lambda functions alias (dev/test/prod).
基本上我想实现的是使用 API 网关的不同阶段 (dev/test/prod) 调用各种 Lambda 函数别名 (dev/test/prod)。
I am totally stucked, I would like to know what are the strategies people have taken to shift lambda traffics, eg.我完全被困住了,我想知道人们采取了哪些策略来转移 lambda 流量,例如。 from LambdaA:dev to LambdaA:prod?
从 LambdaA:dev 到 LambdaA:prod?
I have tried to use "AutoPublishAlias", but in SAM AutoPublishAlias you can't have more then one alias in a single cloudformation stack, so that makes traffic shifting impossible.我曾尝试使用“AutoPublishAlias”,但在 SAM AutoPublishAlias 中,单个 cloudformation 堆栈中的别名不能超过一个,因此无法进行流量转移。
Before using a single stack, I have also used Canary Deployment, it works ok when I separate lambda into multiple envrs (ie. dev-lambaA, test-lambdaA, prod-lambdaA) managed by different cloudformation stack.在使用单个堆栈之前,我还使用了 Canary Deployment,当我将 lambda 分成由不同的 cloudformation 堆栈管理的多个环境(即 dev-lambaA、test-lambdaA、prod-lambdaA)时,它工作正常。 But I would like to reduce the number of lambda functions by only have lambdas reside in a single stack.
但我想通过只让 lambda 驻留在一个堆栈中来减少 lambda 函数的数量。
What you can do is add the following to your template.yaml file:您可以做的是将以下内容添加到您的 template.yaml 文件中:
Resources:
ProductionAPI:
Type: AWS::Serverless::Api
Properties:
StageName: PRD
DefinitionUri: ./prdswagger.yaml
DevelopmentAPI:
Type: AWS::Serverless::Api
Properties:
StageName: DEV
DefinitionUri: ./devswagger.yaml
And use the swagger files to create your endpoints.并使用 swagger 文件创建您的端点。 At every endpoint add an x-amazon-apigateway-integration to the correct lambda version that you are targeting.
在每个端点,将 x-amazon-apigateway-integration 添加到您定位的正确 lambda 版本。
x-amazon-apigateway-integration:
httpMethod: "POST"
type: aws_proxy
uri: "arn:aws:apigateway:eu-central-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-central-1:[account_nr]:function:[myfunctionname]:PRD/invocations"
passthroughBehavior: "when_no_match"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.