Update push.yml to optimize production dependencies and exclude unnec… #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Zip and Update Lambda Function | |
on: | |
push: | |
branches: [main] | |
env: | |
AWS_REGION: "us-east-1" | |
S3_BUCKET: "wavewise" | |
LAMBDA_FUNCTION_NAME: "wavewise-backend" | |
jobs: | |
deploy: | |
name: Deploy to S3 and Update Lambda Function | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials from IAM role | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::851725484938:role/github-aws | |
aws-region: ${{ env.AWS_REGION }} | |
role-session-name: GitHubActionsDeploymentSession | |
- name: Install Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "14" # Use a version that matches your Lambda's runtime | |
- name: Install production dependencies with Yarn | |
run: yarn install --production # Install only production dependencies to reduce size | |
- name: Prune development dependencies | |
run: yarn install --production # Ensure only production dependencies are included | |
- name: Zip project directory excluding unnecessary files | |
run: zip -r wavewise-backend.zip . -x "*.git*" "*node_modules/dev-dependencies*" "*tests*" "*docs*" | |
- name: Upload zip to S3 | |
run: aws s3 cp wavewise-backend.zip s3://${{ env.S3_BUCKET }}/${{ env.LAMBDA_FUNCTION_NAME }}.zip | |
- name: Update Lambda function code from S3 | |
run: | | |
aws lambda update-function-code \ | |
--function-name ${{ env.LAMBDA_FUNCTION_NAME }} \ | |
--s3-bucket ${{ env.S3_BUCKET }} \ | |
--s3-key ${{ env.LAMBDA_FUNCTION_NAME }}.zip |