How to automate deploying to environments with AWS Copilot CLI?

Needless to say, I am new to AWS. Excuse me.

I had a simple static site project (HTML/CSS/JS/PNG). Then put my files from root to /src, and npm init on root and amongst other things installed webpack dependency with which I can compile minimized and optimized files to the /dist directory. npm run build runs webpack. This works perfectly.

Next I installed AWS Copilot CLI and initializes service which generated /copilot/{project-name}/manifest.yml file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>name: {project-name}
type: Static Site
http:
redirect_to_https: true
path: '/'
alias: 'dev-{project-name}.{company}.{ltd}'
files:
- source: dist
recursive: true
environments:
stage:
http:
alias: 'staging-{project-name}.{company}.{ltd}'
prod:
http:
alias: '{project-name}.{company}.{ltd}'
</code>
<code>name: {project-name} type: Static Site http: redirect_to_https: true path: '/' alias: 'dev-{project-name}.{company}.{ltd}' files: - source: dist recursive: true environments: stage: http: alias: 'staging-{project-name}.{company}.{ltd}' prod: http: alias: '{project-name}.{company}.{ltd}' </code>
name: {project-name}

type: Static Site

http:
  redirect_to_https: true
  path: '/'
  alias: 'dev-{project-name}.{company}.{ltd}'

files:
  - source: dist
    recursive: true

environments:
  stage:
    http:
      alias: 'staging-{project-name}.{company}.{ltd}'
  prod:
    http:
      alias: '{project-name}.{company}.{ltd}'

Now I can manually build the dist folder with npm run build and then use copilot svc deploy and choose either of the three environments (development, stage, prod), and the generated files automatically show up in their respective S3 buckets, and all three websites work and have the SSL certificate. That is already amazing.

Next step, I would like to automate all three deploys on commit+push/merge to the main branch. I added /copilot/environments/{development/prod/stage}/manifest.yml files, and they are correct. Then with copilot pipeline init two more files were generated, /copilot/pipelines/{project-name}-main/{buildspec/manifest}.yml. I’ve edited them a bit while playing around, but I cannot seem to get them to work properly. On code commit to BitBucket repo, AWS CodePipeline recognizes the change and starts the pipeline in stages Source -> Build -> DeployTo-development -> DeployTo-stage -> DeployTo-prod.

There are two problems.

  1. The pipeline does not respect the requires_approval: true limitation and all stages go through and are successfully completed.
  2. Absolutely nothing updates in the S3 buckets.

I don’t know if something is wrong in my manifest/buildspec files or is there some hidden configuration in the AWS CodePipeline UI…

/copilot/pipelines/{project-name}-main/manifest.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>name: {project-name}-main
version: 1
source:
provider: Bitbucket
properties:
branch: main
repository: https://bitbucket.org/{company-name}/{project-name}
# connection_name: a-connection
stages:
- name: development
# test_commands: [echo 'running tests', make test]
# deployments:
# {project-name}:
# template_path: infrastructure/development.env.yml
# template_config: infrastructure/development.env.params.json
# stack_name: {company-name}-development
- name: stage
requires_approval: true
# deployments:
# {project-name}:
# template_path: infrastructure/stage.env.yml
# template_config: infrastructure/stage.env.params.json
# stack_name: {company-name}-stage
- name: prod
requires_approval: true
# deployments:
# {project-name}:
# template_path: infrastructure/prod.env.yml
# template_config: infrastructure/prod.env.params.json
# stack_name: {company-name}-prod
</code>
<code>name: {project-name}-main version: 1 source: provider: Bitbucket properties: branch: main repository: https://bitbucket.org/{company-name}/{project-name} # connection_name: a-connection stages: - name: development # test_commands: [echo 'running tests', make test] # deployments: # {project-name}: # template_path: infrastructure/development.env.yml # template_config: infrastructure/development.env.params.json # stack_name: {company-name}-development - name: stage requires_approval: true # deployments: # {project-name}: # template_path: infrastructure/stage.env.yml # template_config: infrastructure/stage.env.params.json # stack_name: {company-name}-stage - name: prod requires_approval: true # deployments: # {project-name}: # template_path: infrastructure/prod.env.yml # template_config: infrastructure/prod.env.params.json # stack_name: {company-name}-prod </code>
name: {project-name}-main

version: 1

source:
  provider: Bitbucket
  properties:
    branch: main
    repository: https://bitbucket.org/{company-name}/{project-name}
    # connection_name: a-connection

stages:
  - name: development
    # test_commands: [echo 'running tests', make test]
    # deployments:
    #   {project-name}:
    #     template_path: infrastructure/development.env.yml
    #     template_config: infrastructure/development.env.params.json
    #     stack_name: {company-name}-development

  - name: stage
    requires_approval: true
    # deployments:
    #   {project-name}:
    #     template_path: infrastructure/stage.env.yml
    #     template_config: infrastructure/stage.env.params.json
    #     stack_name: {company-name}-stage

  - name: prod
    requires_approval: true
    # deployments:
    #   {project-name}:
    #     template_path: infrastructure/prod.env.yml
    #     template_config: infrastructure/prod.env.params.json
    #     stack_name: {company-name}-prod

/copilot/pipelines/{project-name}-main/buildspec.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>version: 0.2
env:
variables:
NODE_ENV: development
DEBUG: false
# Note: This place is NOT meant for secrets (use parameter-store or secrets-manager instead)
# Note: Any env var defined here overrides existing ones (eg. Docker vars)
phases:
install:
runtime-versions:
nodejs: 20.x
commands:
- cd $CODEBUILD_SRC_DIR
- wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.33.4
- mv ./copilot-linux-v1.33.4 ./copilot-linux
- chmod +x ./copilot-linux
- npm install
# pre_build:
# commands:
# - node --version # v20.11.1
# - npm --version # 10.2.4
# - aws --version # aws-cli/2.15.43 Python/3.11.8 Linux/4.14.291-218.527.amzn2.x86_64 exec-env/AWS_ECS_EC2 exe/x86_64.amzn.2023 prompt/off
# - ./copilot-linux --version # copilot version: v1.33.4
# - echo $CODEBUILD_SRC_DIR # /codebuild/output/src{some-numbers}/src
build:
commands:
- npm run build
- ls -lah ./dist
post_build:
commands:
- export COLOR="false"
- export CI="true"
- pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/{project-name}-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
- stages=$(echo $pipeline | jq -r '.stages[].name')
- >
for env in $stages; do
./copilot-linux env package -n $env --output-dir './infrastructure' --upload-assets --force;
if [ $? -ne 0 ]; then
echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
exit 1;
fi
done;
- echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>"
- echo $CODEBUILD_SRC_DIR
- ls -lah ./dist
- ls -lah ./infrastructure
artifacts:
files:
- "infrastructure/*"
</code>
<code>version: 0.2 env: variables: NODE_ENV: development DEBUG: false # Note: This place is NOT meant for secrets (use parameter-store or secrets-manager instead) # Note: Any env var defined here overrides existing ones (eg. Docker vars) phases: install: runtime-versions: nodejs: 20.x commands: - cd $CODEBUILD_SRC_DIR - wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.33.4 - mv ./copilot-linux-v1.33.4 ./copilot-linux - chmod +x ./copilot-linux - npm install # pre_build: # commands: # - node --version # v20.11.1 # - npm --version # 10.2.4 # - aws --version # aws-cli/2.15.43 Python/3.11.8 Linux/4.14.291-218.527.amzn2.x86_64 exec-env/AWS_ECS_EC2 exe/x86_64.amzn.2023 prompt/off # - ./copilot-linux --version # copilot version: v1.33.4 # - echo $CODEBUILD_SRC_DIR # /codebuild/output/src{some-numbers}/src build: commands: - npm run build - ls -lah ./dist post_build: commands: - export COLOR="false" - export CI="true" - pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/{project-name}-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))') - stages=$(echo $pipeline | jq -r '.stages[].name') - > for env in $stages; do ./copilot-linux env package -n $env --output-dir './infrastructure' --upload-assets --force; if [ $? -ne 0 ]; then echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2; exit 1; fi done; - echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>" - echo $CODEBUILD_SRC_DIR - ls -lah ./dist - ls -lah ./infrastructure artifacts: files: - "infrastructure/*" </code>
version: 0.2

env:
  variables:
    NODE_ENV: development
    DEBUG: false
    # Note: This place is NOT meant for secrets (use parameter-store or secrets-manager instead)
    # Note: Any env var defined here overrides existing ones (eg. Docker vars)

phases:
  install:
    runtime-versions:
      nodejs: 20.x
    commands:
      - cd $CODEBUILD_SRC_DIR

      - wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.33.4
      - mv ./copilot-linux-v1.33.4 ./copilot-linux
      - chmod +x ./copilot-linux

      - npm install

  # pre_build:
  #   commands:
  #     - node --version            # v20.11.1
  #     - npm --version             # 10.2.4
  #     - aws --version             # aws-cli/2.15.43 Python/3.11.8 Linux/4.14.291-218.527.amzn2.x86_64 exec-env/AWS_ECS_EC2 exe/x86_64.amzn.2023 prompt/off
  #     - ./copilot-linux --version # copilot version: v1.33.4
  #     - echo $CODEBUILD_SRC_DIR   # /codebuild/output/src{some-numbers}/src

  build:
    commands:
      - npm run build

      - ls -lah ./dist

  post_build:
    commands:
      - export COLOR="false"
      - export CI="true"
      - pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/{project-name}-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
      - stages=$(echo $pipeline | jq -r '.stages[].name')
      - >
        for env in $stages; do
          ./copilot-linux env package -n $env --output-dir './infrastructure' --upload-assets --force;
          if [ $? -ne 0 ]; then
            echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
            exit 1;
          fi
        done;

      - echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>"
      - echo $CODEBUILD_SRC_DIR
      - ls -lah ./dist
      - ls -lah ./infrastructure

artifacts:
  files:
    - "infrastructure/*"

In the “CodePipeline > Build” output I can see all files are in the /dist folder, despite them not being in the repo, so npm run build works correctly. Any help will be greatly appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật