我注意到,我的SAM部署正在使用我对自定义API网关响应所做的更改来更新API Gateway的配置,但实际上并没有将它们部署到API Gateway阶段以使其生效。在SAM部署之后,如果我进入API网关控制台,选择我的API,打开Actions菜单,选择deploy API,选择my stage,然后点击deploy the changes,do go live go。要让SAM deploy将更新的配置部署到stage,我还需要执行其他步骤吗?
我做了一个重现这个问题的例子,下面是我的template.yml
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar
Parameters:
ProjectId:
Type: String
Description: CodeStar projectId used to associate new resources to team members
CodeDeployRole:
Type: String
Description: IAM role to allow AWS CodeDeploy to manage deployment of AWS Lambda functions
Stage:
Type: String
Description: The name for a project pipeline stage, such as Staging or Prod, for which resources are provisioned and deployed.
Default: "Prod"
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Sub "${Stage}"
MissingAuthGatewayResponse:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseTemplates:
application/json: "{'message': 'Not found.'}"
ResponseType: MISSING_AUTHENTICATION_TOKEN
RestApiId: !Ref MyApi
StatusCode: "403"
HelloWorld:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "awscodestar-${ProjectId}-lambda-HelloWorld"
Handler: index.handler
Runtime: python3.7
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Events:
GetEvent:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /
Method: get
LambdaExecutionRole:
Description: Creating service role in IAM for AWS Lambda
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "CodeStar-${ProjectId}-Execution${Stage}"
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com]
Action: sts:AssumeRole
Path: /
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
PermissionsBoundary: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary"
Outputs:
ApiURL:
Description: "API URL"
Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/"
发布于 2020-07-30 20:20:54
是啊。我发现这种行为也很烦人。让我们添加另一个类型为AWS::ApiGateway::Deployment
的资源,并使用RestApiId
属性连接到您的Api。现在,当您使用sam deploy
时,它将使用提供的StageName
部署您的api。
Resources
...
ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- HelloWorld
Properties:
RestApiId:
Ref: MyApi
StageName: !Sub "${Stage}"
发布于 2021-02-18 16:46:01
我也遇到了同样的问题:部署已经完成,但没有更新stage。问题是cloudformation不考虑具有相同名称的部署,所以如果您修改部署名称,它将按预期重新部署。
为了解决这个问题,我们使用了这个插件https://github.com/paprins/serverless-apigateway-deployment-timestamp,它基本上是在部署的名称上添加了一个时间戳。例如,此部署
MyDeployment:
Type: AWS::ApiGateway::Deployment
完成的部署如下所示
APIProxyDeployment19878797197:
Type: AWS::ApiGateway::Deployment
另一种选择是预处理描述符,修改部署名称,但对我来说,插件是更简单的解决方案。
https://stackoverflow.com/questions/63166411
复制相似问题