繁体   English   中英

AWS SAM:部署期间阶段已存在错误

[英]AWS SAM: Stage already exists error during deployment

我正在尝试部署一个简单的 API 网关,该网关与 Lambda function 集成。 我正在使用 GitLab CICD 来部署资源,但即使尝试了这么多修复程序,我似乎也无法成功部署它。 下面是我正在使用的 YAML 模板。

Resources:
  MyFunction: 
    Type: AWS::Serverless::Function 
      FunctionName : MyFunctionName
      CodeUri: MyFunctionName/
      Handler: app.lambda_handler
      Role: MyRole
      Tags: 
        env : dev
      Architectures:
        - x86_64
      Events:
        MyAPI:
          Type: Api
          Properties:
            Path: /dev
            Method: POST
            RestApiId: 
              Ref: MyAPI
      VpcConfig:
        SecurityGroupIds: <sec grp id>
        SubnetIds: <subnet id>

  MyAPI: 
    Type: AWS::Serverless::Api
    Properties:
      DefinitionBody: 
        swagger: 2.0
        info:
          title: MyAPIName
        host: "xxxxx.execute-api.ap-south-1.amazonaws.com"
        schemes:
          - https        
        basePath: /dev
        paths:
          /:
            post:
              responses: {}
              x-amazon-apigateway-integration:
                type: "aws_proxy"
                httpMethod: "POST"
                uri: "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/<MyFunction ARN>/invocations"
                responses:
                  default:
                    statusCode: "200"
                passthroughBehavior: "when_no_match"
                contentHandling: "CONVERT_TO_TEXT"      
        x-amazon-apigateway-policy:
          Version: '2012-10-17'
          Statement:
          - Effect: Deny
            Principal: "*"
            Action: execute-api:Invoke
            Resource: "*"
            Condition:
              StringNotEquals:
                aws:sourceVpce:
                - vpce-xxxxxx
          - Effect: Allow
            Principal: "*"
            Action: execute-api:Invoke
            Resource: "*"
      EndpointConfiguration:
        Type: PRIVATE
      StageName: dev

  MyAPIDeployment:  
    Type: AWS::ApiGateway::Deployment
    Properties: 
      RestApiId: 
        Ref: MyAPI
      StageName: dev

当我尝试部署上述脚本时,我收到的错误是:(使用 GitLab CI)

dev already exists in stack arn:aws:cloudformation:ap-south-1:xxxx:stack/stackname/xxxx

我在控制台上检查了 API GW 并找到了一个名为 Stage 的阶段(来自较旧的部署)。 但没有“开发”。 认为这是导致问题的原因,我删除了阶段并尝试再次部署。 但它仍然给我同样的错误。 我已经被这个问题困扰了几天,任何形式的帮助都将不胜感激。

检查错误消息中提供的 Cloudformation 堆栈以获取类似的资源名称。 可能 Cloudformation 没有识别出您手动删除了冲突。

要修复它,您应该删除冲突 - 您需要删除 Cloudformation 堆栈(从错误消息中)或更改代码中冲突资源的名称(如果您想使用参数而不是硬编码的环境值,这可能会更容易)。

顺便说一句,您不应该删除使用 CFN 创建的手动资源 - 它可能会导致很多像这样的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM