Skip to content

Instantly share code, notes, and snippets.

@shane-js
Created April 30, 2020 21:13
Show Gist options
  • Save shane-js/3d32ff14bd4d60f18c0441bf47885467 to your computer and use it in GitHub Desktop.
Save shane-js/3d32ff14bd4d60f18c0441bf47885467 to your computer and use it in GitHub Desktop.
S3 Static App Build Commands - Re: Medium Story - Automated Deployment of AWS S3 Static Web App using CloudFormation / SAM and CodePipeline
version: 0.2
#env:
#variables:
# key: "value"
# key: "value"
#parameter-store:
# key: "value"
# key: "value"
#secrets-manager:
# key: secret-id:json-key:version-stage:version-id
# key: secret-id:json-key:version-stage:version-id
#exported-variables:
# - variable
# - variable
#git-credential-helper: yes
phases:
#install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
#runtime-versions:
# name: version
# name: version
#commands:
# - command
# - command
#pre_build:
#commands:
# - command
# - command
build:
commands:
- mkdir localStaticAppBuildDirCopy # make an empty directory so we have a spot to transfer the built React app assets in a moment...
- LATEST_APP_BUILD_ARTIFACT=`aws s3api list-objects --bucket BUCKET_NAME_YOUR_CODEPIPELINE_PUTS_ARTIFACTS --prefix PIPELINE_NAME_OR_PATH/BA_staticW --output text --no-paginate --query 'reverse(sort_by(Contents, &LastModified))[:1].Key'` # depending on a few things 'BA_staticW' may be different in your case, it is simply a cut off of the build artifact we specified early 'BA_staticWebAppBuildDir'
- aws s3 cp s3://BUCKET_NAME_YOUR_CODEPIPELINE_PUTS_ARTIFACTS/${LATEST_APP_BUILD_ARTIFACT} zipped-static-app-build.zip
- unzip zipped-static-app-build.zip -d localStaticAppBuildDirCopy
- aws s3 sync localStaticAppBuildDirCopy s3://YOUR_S3_STATIC_APPS_BUCKET_NAME --delete
# - command
#post_build:
#commands:
# - command
# - command
#reports:
#report-name-or-arn:
#files:
# - location
# - location
#base-directory: location
#discard-paths: yes
#file-format: JunitXml | CucumberJson
#artifacts:
#files:
# - location
# - location
#name: $(date +%Y-%m-%d)
#discard-paths: yes
#base-directory: location
#cache:
#paths:
# - paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment