Reputation: 2928
I am a newbie in using AWS Amplify and I just published my own frontend WebApp with it developed with React. I just zipped my build folder and dropped the resulting zip file in the AWS Console. It is working fine.
However, the job is done manually and I want to automate that. I have CI&CD servers other than the ones in AWS which are working fine for my other services. So what I need is a script to automate what I just did as a I want to reuse my existing CI&CD servers. Having such a script will be really useful as I can reproduce the steps locally or in a docker container.
I know that there is a solution for that: the amplify CLI. However, commands such as amplify init
, amplify configure
and amplify pull
require a lot rights and a lot of user interaction even the AWS profile (with the secret key and access key) has already been configured.
It would be great to do something like this:
amplify deploy build.zip <APP-ARN>
or (in case of a folder)
amplify deploy /build <APP-ARN>
Essentially, I just want to automate what I did manually: uploading the (zipped) build folder to deploy my AWS Amplify app. Thus, this means no user interaction.
How to do this?
Upvotes: 12
Views: 9089
Reputation: 51
I have tried that for a sample React application with the Node Package Manager (npm) as below. Achieved it using github workflow as below
name: CI-CD-Pipeline-to-AWS-Amplify-Manual-Deployment
env:
AMPLIFY_PACKAGE_S3_BUCKET_NAME: "amplify-manual-deploy-trail"
AWS_REGION: "us-west-2"
APP_ID: "ABC123xyz"
PACKAGE_NAME: "build"
on:
push:
branches: ["main"]
jobs:
ci-pipeline:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm run build --if-present
- name: Create Zip Deployment Package
run: cd build && zip -r $PACKAGE_NAME * -x *.git*
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: $AWS_REGION
- name: Copy Deployment Package to AWS S3
run: |
cd build && \
aws s3 cp $PACKAGE_NAME s3://$AMPLIFY_PACKAGE_S3_BUCKET_NAME
cd-pipeline:
runs-on: ubuntu-latest
needs: [ci-pipeline]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: $AWS_REGION
- name: Deploy the new application version
run: |
aws amplify start-deployment \
--app-id $APP_ID \
--branch-name manual \
--source-url s3://$AMPLIFY_PACKAGE_S3_BUCKET_NAME/$PACKAGE_NAME.zip
Upvotes: 2
Reputation: 149
You can achieve what you are trying to do with AWS CLI. If you have an AWS CLI configured in your CI/CD pipeline, you can use the command 'start-deployment.
aws amplify start-deployment --app-id <value> --branch-name <value> --source-url <value>
In the above command use the --source-url param to specify the URL from where Amplify can download the zip file (This URL should be publicly accessible). Once the above command runs, you should be able to see the deployment on the Amplify console screen.
You can also achieve the same using create-deployment and start-deployment commands. With this method, first, you can pass the zip file in the create-deployment command and second, during the start-deployment command, you do not have to use --source-url param. You can see these commands being called in the "Network" tab of developer tools when manually uploading the zip using web UI.
Upvotes: 2
Reputation: 1845
I'm quite new to AWS & Amplify, but I think the design philosophy, including CI/CD would be to spin up a new compute instance with the new Amplify installation and let the load balancer sort things out after stopping obsolete instances. This allows easier rollbacks etc.
Upvotes: 0
Reputation: 1061
Your solution is git, aws amplify has the ability to watch a git repo and detect changes. If there is a change to the branch that you have set it to watch, it will automatically build a new version.
You can set it up to build only frontend or both backend (amplify) and frontend.
Create a git repo. You can use for example github or aws codecommit
Configure your project to publish to that git repo
In AWS Amplify console start a new app or change your existing one, to watch the git repo
Publish changes to the git repo and watch in the amplify console that it automatically builds a new version of your app
Upvotes: 1