Skip to content

Instantly share code, notes, and snippets.

@meltingice
Created June 29, 2017 19:02
Show Gist options
  • Save meltingice/0ef4d9008da79703ae91fcc56f2556a0 to your computer and use it in GitHub Desktop.
Save meltingice/0ef4d9008da79703ae91fcc56f2556a0 to your computer and use it in GitHub Desktop.
AWS Lambda Deploy Script

Project Structure

Put all of your application code (including your package.json and node_modules folder) into a folder in this directory named Package. The entry point is Package/index.js.

Getting Started

  1. Install AWS CLI
    • brew install awscli
  2. Configure AWS CLI
    • aws configure --profile [name of your project]
      • AWS Access Key ID: [paste-access-key-id-here]
      • AWS Secret Access Key: [paste-secret-access-key-here]
      • Default region name: us-east-1
      • Default output format: json
  3. Edit the deploy script to add the name of your Lambda function.

Deploying

After making changes to the package source (under Package/), run ./deploy.sh in the root of the project.

#!/bin/bash
# Create tempoary directory
PACKAGE_DIR=`mktemp -d`
PACKAGE_PATH="$PACKAGE_DIR/package.zip"
pushd Package
# Create deployment package
zip -r -X "$PACKAGE_PATH" ./
# Upload package to AWS Lambda
aws lambda update-function-code \
--function-name [name of your lambda function] \
--zip-file "fileb://$PACKAGE_PATH" \
--profile [name of your project]
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment