GitHub Actions are a powerful way to automate workflows helping you build, test and deploy your code. The marketplace is rapidly growing with new actions being added every day, doing everything from posting to Slack to deploying to AWS.
The following are some actions to help you deploy your code to Amazon AWS, enjoy!
To be able to deploy your code to AWS, you’ll first need to specify your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY keys under your Settings > Secrets in your repo.
After adding the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets, it should look like this.
And now your can access those AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY values in your action, sweet!
${{ secrets.AWS_ACCESS_KEY_ID }}
${{ secrets.AWS_SECRET_ACCESS_KEY }}
Deploy Node.js To AWS Beanstalk
This action will deploy Node.js app to AWS Beanstalk, just edit the variables:
- MY_BEANSTALK_APPLICATION your Beanstalk app name
- MY_BEANSTALK_ENVIRONMENT your Beanstalk environment
- MY_AWS_REGION your AWS region
name: Deploy To Beanstalkon:
push:
branches:
- masterjobs:
build:
runs-on: ubuntu-lateststrategy:
matrix:
node-version: [10.x]steps:
- uses: actions/checkout@v1
- name: Use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Run npm install, lint
run: |
npm ci
npm install
npm run lint
- name: Generate deployment package
run: zip -r package.zip . -x ".git/*" -x ".github/*" -x ".vscode/*"
- name: Get timestamp
id: timestamp
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H-%M-%S-%3NZ')"
- name: Run beanstalk deploy
uses: einaregilsson/beanstalk-deploy@v2
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: MY_BEANSTALK_APPLICATION
environment_name: MY_BEANSTALK_ENVIRONMENT
region: MY_AWS_REGION
version_label: "${{ steps.timestamp.outputs.date }}"
deployment_package: package.zip
Deploy Vue.js To AWS S3 & Cloudfront
This action will deploy a Vue.js app to AWS S3 and invalidate the AWS Cloudfront distribution.
- MY_S3_BUCKET your S3 bucket name
- MY_CLOUDFRONT_DISTRIBUTION your Cloudfront distribution id
- MY_AWS_REGION your AWS region
name: Deploy To S3 & Cloudfronton:
push:
branches:
- masterjobs:
build:runs-on: ubuntu-lateststrategy:
matrix:
node-version: [10.x]steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Run npm install, lint, build
run: |
npm ci
npm install
npm run lint
npm run prod:test- name: Run s3-sync-action
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_BUCKET: MY_S3_BUCKET
AWS_REGION: 'MY_AWS_REGION'
SOURCE_DIR: './dist'
- name: Run invalidate-cloudfront-action
uses: chetan/invalidate-cloudfront-action@master
env:
PATHS: '/*'
AWS_REGION: 'MY_AWS_REGION'
DISTRIBUTION: 'MY_CLOUDFRONT_DISTRIBUTION'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Deploy Ruby On Rails To AWS Beanstalk
This action can deploy Ruby On Rails app to AWS Beanstalk.
- MY_BEANSTALK_APPLICATION your Beanstalk app name
- MY_BEANSTALK_ENVIRONMENT your Beanstalk environment
- MY_AWS_REGION the AWS region being deployed to
For instructions on how to deploy Rails 6 to AWS Beanstalk, read my previous post Deploying Rails 6 To AWS Beanstalk.
name: Deploy To Beanstalkon:
push:
branches:
- masterjobs:
build:runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Generate package
uses: thedoctor0/zip-release@master
with:
filename: 'package.zip'
exclusions: '*.git* /*node_modules/* /*test/* *.md'- name: Current timestamp
id: timestamp
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H-%M-%S-%3NZ')"
- name: Beanstalk deploy
uses: einaregilsson/beanstalk-deploy@v2
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: MY_BEANSTALK_APPLICATION
environment_name: MY_BEANSTALK_ENVIRONMENT
region: MY_AWS_REGION
version_label: "${{ steps.timestamp.outputs.date }}"
deployment_package: package.zip
Note, these actions are triggered whenever you push to the master branch. For Production builds, you’ll probably only want to deploy when a specific release tag is created.
on:
push:
tags:
- release-*
What actions have you created? I’d love to hear about them in the comments!
PS, if this article helped you, please give it a few claps 👏