使用 Bitbucket Pipelines 通过 AWS CodeDeploy 部署到多个 AWS 区域

Using Bitbucket Pipelines to deploy to multiple AWS regions using AWS CodeDeploy

我有一个现有的 Bitbucket Pipelines 设置,它使用 AWS CodeDeploy 在单个区域上运行。现在我正在尝试修改现有设置以适应多区域部署。这是我的 bitbucket-pipelines.yml:

image: php:7.1.29

pipelines:
  branches:
    develop:
      - step:
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip zip
            - zip -r MobileAPIDEV.zip .
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'MobileAPIDEV'
                ZIP_FILE: 'MobileAPIDEV.zip'
                COMMAND: 'upload' 
                S3_BUCKET: $S3_BUCKET
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'MobileAPIDEV'
                DEPLOYMENT_GROUP: 'MobileAPIDEV'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
    master:
      - step:
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip zip
            - zip -r prodMobileAPI.zip .
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'prodMobileAPI'
                ZIP_FILE: 'prodMobileAPI.zip'
                COMMAND: 'upload' 
                S3_BUCKET: $S3_BUCKET
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
                APPLICATION_NAME: 'prodMobileAPI'
                DEPLOYMENT_GROUP: 'prodMobileAPI'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
                AWS_DEFAULT_REGION: eu-central-1 
                APPLICATION_NAME: 'prodMobileAPI'
                DEPLOYMENT_GROUP: 'prodMobileAPI'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'

我在 master 分支下添加了第三个 pipe 并将 eu-central-1 设置为新的默认区域。我不确定我这样做是否正确,因为我找不到使用这种方法进行多区域部署的任何示例。

当我尝试部署时,出现此错误:An error occurred (RevisionDoesNotExistException) when calling the GetApplicationRevision operation: No application revision found for revision.

我确认我在其他区域的 CodeDeploy 设置具有正确的角色,并且我用于 Bitbucket 管道的访问密钥也具有足够的权限。

来自错误

An error occurred (RevisionDoesNotExistException) when calling the GetApplicationRevision operation: No application revision found for revision.

提到的地区没有可用的神器eu-central-1 RevisionDoesNotExistException

根据 documentation

When you create or edit a pipeline, you must have an artifact bucket in the pipeline Region and then you must have one artifact bucket per Region where you plan to execute an action.

所以你还必须有一个 upload 部分 OR

我会做的是每个 region OR

有一个单独的步骤

设置 Cross-Region Replication for Amazon S3,这样我就可以复制我想要的任何区域的文章,而且我只能在 pipeline.yml

中有一个 upload

查看此博客 post Using AWS CodePipeline to Perform Multi-Region Deployments


pipelines:
  branches:
    develop:
      - step:
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip zip
            - zip -r MobileAPIDEV.zip .
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'MobileAPIDEV'
                ZIP_FILE: 'MobileAPIDEV.zip'
                COMMAND: 'upload' 
                S3_BUCKET: $S3_BUCKET
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'MobileAPIDEV'
                DEPLOYMENT_GROUP: 'MobileAPIDEV'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
    master:
      - step:
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip zip
            - zip -r prodMobileAPI.zip .
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION 
                APPLICATION_NAME: 'prodMobileAPI'
                ZIP_FILE: 'prodMobileAPI.zip'
                COMMAND: 'upload' 
                S3_BUCKET: $S3_BUCKET
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
                APPLICATION_NAME: 'prodMobileAPI'
                DEPLOYMENT_GROUP: 'prodMobileAPI'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
                AWS_DEFAULT_REGION: 'eu-central-1'
                APPLICATION_NAME: 'prodMobileAPI'
                ZIP_FILE: 'prodMobileAPI.zip'
                COMMAND: 'upload' 
                S3_BUCKET: $S3_BUCKET
            - pipe: atlassian/aws-code-deploy:0.5.3
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID 
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
                AWS_DEFAULT_REGION: 'eu-central-1' 
                APPLICATION_NAME: 'prodMobileAPI'
                DEPLOYMENT_GROUP: 'prodMobileAPI'
                WAIT: 'false'
                S3_BUCKET: $S3_BUCKET
                COMMAND: 'deploy' 
                IGNORE_APPLICATION_STOP_FAILURES: 'true'
                FILE_EXISTS_BEHAVIOR: 'OVERWRITE'