我希望能够部署到我想要的阶段而不影响其他阶段,例如,我想一直部署到开发阶段,然后部署到prod而不影响开发阶段
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: REGIONAL
StageName: Dev
OpenApiVersion: "3.0"
Name: asaf_api_second
Description: "my api from sam"
如果我改变StageName刺激阶段开发将删除,我怎么能阻止呢?
所需的解决方案包括以下步骤:
-
您需要将阶段定义为根级别的参数:
Parameters: stage: Default: dev Description: StageName of API Gateway deployment Type: String Resources...
-
在资源定义中的阶段参数名称中添加使用(!Ref)的引用:
Resources: ApiGatewayApi: Type: AWS::Serverless::Api Properties: EndpointConfiguration: REGIONAL StageName: !Ref stage OpenApiVersion: "3.0" Name: asaf_api_second Description: "my api from sam"
-
当您想要部署到prod时,使用cli或toml文件覆盖部署命令中所需的阶段参数:
sam deploy --parameter-overrides stage=prod