/sample-simple-invoke-lambda

Create node and python lambda from simple make targets using AWS CLI and invoke them

Primary LanguageMakefile

Simple AWS CLI Sample with Lambda

Use three different methods via the CLI to create and invoke a Lambda. Create node and python lambda from simple make targets.

makefile uses these three different ways to configure the AWS CLI. Uncomment the one you want to use.

#AWS_CLI=AWS_PROFILE=localstack aws
#AWS_CLI=AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url http://localhost:4566 --region us-east-1
#AWS_CLI=awslocal

"Design"

Setup

After you've cloned this repo. You can either use a LocalStack AWS_PROFILE for credentials, or use awslocal. Setup options are directly below.

With LocalStack Profile

  1. Setup an AWS_PROFILE for LocalStack

Add this to your ~/.aws/config file

[profile localstack]
region=us-east-1
output=json
endpoint_url = http://localhost:4566

Add this to your ~/.aws/credentials file

[localstack]
aws_access_key_id=test
aws_secret_access_key=test

With awslocal wrapper

  1. Create a Python venv and activate it

    make setup-venv
    source venv/bin/activate
  2. Change makefile to point at awslocal

#AWS_CLI=AWS_PROFILE=localstack aws
#AWS_CLI=AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url http://localhost:4566 --region us-east-1
AWS_CLI=awslocal

With AWS CLI

Change makefile to point at aws CLI. Must be AWS CLI v2.

#AWS_CLI=AWS_PROFILE=localstack aws
AWS_CLI=AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url http://localhost:4566 --region us-east-1
#AWS_CLI=awslocal

Run LocalStack

You can use LocalStack Pro, just see the commented out line in docker-compose.yml.

docker compose up

Python Lambda Test

  1. Build python function zip
make bundle-py
  1. Deploy function
make create-py-function
  1. Invoke function
make local-py-invoke
  1. See results
cat output.txt

Node Lambda Test

  1. Build python function zip
make bundle
  1. Deploy function
make create-function
  1. Invoke function
make local-invoke
  1. See results
cat output.txt