Skip to content

Instantly share code, notes, and snippets.

@hadynz
Created May 26, 2020 09:44
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save hadynz/b4e190e0ce10e5811cb462920a9c678f to your computer and use it in GitHub Desktop.
Save hadynz/b4e190e0ce10e5811cb462920a9c678f to your computer and use it in GitHub Desktop.
Serverless deploy with state management in S3
name: Continuous deploy
on:
push:
branches: [master]
jobs:
serverless-deploy:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Download `.serverless` state from S3
run: aws s3 sync s3://my-bucket/my-repo-name/env-name/.serverless .serverless --delete
- name: Deploy to AWS
run: npm run deploy
- name: Upload `.serverless` state to S3
run: aws s3 sync .serverless s3://my-bucket/my-repo-name/env-name/.serverless --delete
@Mozart409
Copy link

Hi, do I need to create my bucket before or will it be created via this name "s3://my-bucket/my-repo-name/env-name" ?

@hadynz
Copy link
Author

hadynz commented May 29, 2021

Hi, do I need to create my bucket before or will it be created via this name "s3://my-bucket/my-repo-name/env-name" ?

Yes, that's right. You will need to ensure that the S3 bucket exists. Either create it manually or look into adding an extra step that does that for you.

@Mozart409
Copy link

thank you 👍

@Talhafayyaz11
Copy link

@hadynz Hi, can please clarify what is my-repo-name and env-name here. I tried this but while uploading it exits with error code 255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment