This is a demonstration of how to automatically deploy a sample Node.js app to AWS Elastic Beanstalk whenever a git branch is pushed to GitHub.
- access key ID (stored in GitHub Settings > Secrets as
AWS_ACCESS_KEY_ID
) - secret access key (stored in GitHub Settings > Secrets as
AWS_SECRET_ACCESS_KEY
)
For instruction on obtaining AWS Elastic Beanstalk user credentials, see the tutorial Set up the Elastic Beanstalk Command Line Interface.
- application name
- environment name
- AWS region name (ex. us-west-2)
For instructions on creating an application in Elastic Beanstalk, see the tutorial Getting started using Elastic Beanstalk
An app-specific bash script that populates the build folder contents by:
- copying source files to build folder.
- changing local
images/
URLs to CloudFront URLs - running
npm install --only=production
to add node modules to build folder.
Contains the specific build instructions:
- BUILD_SOURCES - the source files to add to build folder
- SED_* = instructions to change the
images
URLs to CloudFront
A bash script that creates the deploy.zip
file for uploading.
A GitHub Actions file that runs when the main branch is pushed. Steps:
- check out the main branch
- runs build.sh to populate the build folder
- runs the make-deploy script to create deploy.zip
- runds the Beanstalk Deploy to deploy a new version to AWS
The deployed public site is:
githubebdemo.us-west-2.elasticbeanstalk.com
The sample is a node.js app, so seeing anything displayed means that the app is
running. The app uses roundToFixed
as a node module, so roundToFixed was
loaded means that the module was correctly loaded during the build process.
The AWS user credentials must be stored in the GitHub Settings > Secrets page:
After a deploy, the GitHub repo's actions > summary page:
After a successful deploy, the Elastic Beanstalk > Environments page:
Checkout V2 (1.4k stars)
Checks-out your repository under $GITHUB_WORKSPACE
, so your workflow can
access it.
Get current package version (28 stars)
Retrieves the package version from the package.json file and sets the
version in the current-version
output value.
Beanstalk Deploy (158 stars)
Deploy apps to AWS Elastic Beanstalk. It takes the application name, environment name, version name, region and filename as parameters, uploads the file to S3, creates a new version in Elastic Beanstalk, and then deploys that version to the environment. Note: Requires a zip file as the source.
Developer Guide - Serving static files
The following example configuration file tells the proxy server to serve files in the statichtml folder at the path /html, and files in the staticimages folder at the path /images.
Example .ebextensions/static-files.config
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/html: statichtml
/images: staticimages