Skip to content
Search

AWS:CLI:Amplify

lastmod 2025-02-13created 2023-02-0815 edits

Help

docker run --rm -it amazon/aws-cli amplify help

create-deployment

Creates a deployment for a manually deployed Amplify app. Manually deployed apps are not connected to a repository.

docker run --rm -it amazon/aws-cli amplify create-deployment help

SYNOPSIS:

            create-deployment
          --app-id <value>
          --branch-name <value>
          [--file-map <value>]
          [--cli-input-json | --cli-input-yaml]
          [--generate-cli-skeleton <value>]
          [--debug]
          [--endpoint-url <value>]
          [--no-verify-ssl]
          [--no-paginate]
          [--output <value>]
          [--query <value>]
          [--profile <value>]
          [--region <value>]
          [--version <value>]
          [--color <value>]
          [--no-sign-request]
          [--ca-bundle <value>]
          [--cli-read-timeout <value>]
          [--cli-connect-timeout <value>]
          [--cli-binary-format <value>]
          [--no-cli-pager]
          [--cli-auto-prompt]
          [--no-cli-auto-prompt]

file-map

An optional file map that contains file names as keys and file content md5 hashes as values. If this argument is provided, the service generates a unique upload URL per file. Otherwise, the service generates only a single upload URL for the zipped files.

start-deployment

Starts a deployment for a manually deployed app. Manually deployed apps are not connected to a repository.

docker run --rm -it amazon/aws-cli amplify start-deployment help

SYNOPSIS:

            start-deployment
          --app-id <value>
          --branch-name <value>
          [--job-id <value>]
          [--source-url <value>]
          [--cli-input-json | --cli-input-yaml]
          [--generate-cli-skeleton <value>]
          [--debug]
          [--endpoint-url <value>]
          [--no-verify-ssl]
          [--no-paginate]
          [--output <value>]
          [--query <value>]
          [--profile <value>]
          [--region <value>]
          [--version <value>]
          [--color <value>]
          [--no-sign-request]
          [--ca-bundle <value>]
          [--cli-read-timeout <value>]
          [--cli-connect-timeout <value>]
          [--cli-binary-format <value>]
          [--no-cli-pager]
          [--cli-auto-prompt]
          [--no-cli-auto-prompt]

How to deploy from the command line

Create an AWS IAM user

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "amplify:StartDeployment",
            "Resource": "arn:aws:amplify:REGION:ACCOUNT_ID:apps/APP_ID/*"
        }
    ]
}

You need to replace REGION, ACCOUNT_ID, and APP_ID with the relevant values. If you want, you can go further and restrict it to a specific branch.

The important point is that ACCOUNT_ID and APP_ID are UIDs, not names. You can find the UID by checking each ARN entry in the management console.

As an example, if

  • Seoul location (ap-northeast-2)
  • ID of the user registered in AWS IAM (351828347590)
  • ID written in the ARN of AWS Amplify (d3hmwa8f0z10dn)
  • Branch name of AWS Amplify (production)

then:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "amplify:StartDeployment",
            "Resource": "arn:aws:amplify:ap-northeast-2:351828347590:apps/d3hmwa8f0z10dn/branches/production/*"
        }
    ]
}

WARNING

Importantly, you must add an asterisk (/*) wildcard at the end of the ARN to include all sub-resources.

and the AWS CLI command line is

APP_ID="d3hmwa8f0z10dn"
BRANCH_NAME="production"
SOURCE_URL="https://your.gitlab.address/api/v4/projects/112/jobs/5876/artifacts/archive.zip?private_token=..."

aws amplify start-deployment --app-id $APP_ID --branch-name $BRANCH_NAME --source-url $SOURCE_URL --debug

.

Configure GitLab CI/CD variables

Create the following variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION

Then add masking settings so they are not printed in the logs.

build:
  script:
    - apt-get update
    - apt-get install zip -y
    - echo "JOB_ID=$CI_JOB_ID" > build.env
    - npm run build
    - zip -r -j dist.zip dist 
  artifacts:
    paths:
      - dist.zip
    reports:
      dotenv: build.env

deploy:
  image: 
    name: amazon/aws-cli
    entrypoint: [""]
  variables:
    APP_ID: app_id
    BRANCH_NAME: branch_name
    SOURCE_URL: $CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/$JOB_ID/artifacts/dist.zip?job=build&job_token=$CI_JOB_TOKEN
  script:
    - aws amplify start-deployment --app-id $APP_ID --branch-name $BRANCH_NAME --source-url $SOURCE_URL
  needs:
    - build

If artifacts:reports:dotenv is not available, you must save the environment variables to a file yourself and pass them to deploy.

Troubleshooting

UnrecognizedClientException

An error occurred (UnrecognizedClientException) when calling the StartDeployment operation: The security token included in the request is invalid.

Double-check AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

See also

author Zer0 sitemap