如何使用SAM到SPESIFIC阶段部署到AWS而不影响其他阶段?

发布于 2025-02-12 12:24:28 字数 365 浏览 4 评论 0原文

我希望能够在不影响其他阶段的情况下部署到想要的阶段,例如,我想一直部署DEV,然后将其部署到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来制作阶段dev dev会删除,我该如何预防?

I want to be able to deploy to which stage I want without affecting other stages, for example, I want to deploy all the time to dev, and then deploy to prod without effect the dev stage

Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      EndpointConfiguration: REGIONAL
      StageName: Dev
      OpenApiVersion: "3.0"
      Name: asaf_api_second
      Description: "my api from sam"

if I change the StageName to Prod the stage Dev will delete, how can I prevent that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑咖 2025-02-19 12:24:28

所需的解决方案包括以下步骤:

  1. 您需要将阶段定义为根级别的参数:

     参数: 
      阶段:
        默认值:dev
        描述:API网关部署的散打
        类型:字符串
    
    资源...
     
  2. 在资源定义中使用(!ref)添加(!ref)的参考文献:

     资源:
      APIGATEWAAPI:
        类型:aws :: serverless :: api
        特性:
          端点配置:区域
          Stagename:!ref阶段
          开放式:“ 3.0”
          名称:asaf_api_second
          描述:“我来自山姆的API”
     
  3. 要部署到prod时,使用CLI或TOML文件中的部署命令中覆盖所需的阶段参数:

      SAM部署 - 参数跨越阶段= prod
     

The required solution includes the following steps:

  1. You will need to define the stage as a parameter in the root level:

    Parameters: 
      stage:
        Default: dev
        Description: StageName of API Gateway deployment
        Type: String
    
    Resources...
    
  2. Add a reference using (!Ref) to the stage parameter name in the resource definition:

    Resources:
      ApiGatewayApi:
        Type: AWS::Serverless::Api
        Properties:
          EndpointConfiguration: REGIONAL
          StageName: !Ref stage
          OpenApiVersion: "3.0"
          Name: asaf_api_second
          Description: "my api from sam"
    
  3. When you want to deploy to prod, override the required stage parameter in the deploy command using cli or in the toml file:

    sam deploy --parameter-overrides stage=prod
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文