Skip to content

Commit

Permalink
Add information about how to run lambda locally
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjswift committed Dec 25, 2020
1 parent b4fb084 commit 78c2a6c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ target/lambda/release/email_lambda: Cargo.lock $(SHARED_SRC) $(LAMBDA_SRC)
-v ${HOME}/.cargo/git:/root/.cargo/git \
softprops/lambda-rust:${V_LAMBDA_RUST}

target/lambda/runnable/fn:
mkdir -p target/lambda/runnable/fn

target/lambda/runnable/fn/bootstrap: target/lambda/runnable/fn target/lambda/release/email_lambda
cp target/lambda/release/email_lambda $@

# Build a zip archive which can be uploaded to AWS lambda
email_lambda.zip: target/lambda/release/email_lambda
cp ./target/lambda/release/email_lambda ./bootstrap \
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ have:
- A DynamoDB table name
- AWS credentials in the environment that can access both

### Localstack

An emulation of the DynamoDB and SQS resources can be created with Docker and
the [localstack][localstack] image.
[`docker-compose.yml`](./docker-compose.yml) is configured to start localstack
with these services but starting the image does not configure DynamoDB tables
or SQS queues.

```shell
# Create an SQS queue called emails_local
aws --endpoint-url=http://localhost:4566 \
sqs create-queue \
--queue-name=emails_local
# Create a DynamoDB table called emails_local
aws --endpoint-url=http://localhost:4566 \
dynamodb create-table \
--attribute-definitions=AttributeName=EmailId,AttributeType=S \
--table-name=emails_local \
--key-schema=AttributeName=EmailId,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
```

[localstack]: https://github.com/localstack/localstack

### Test

```shell
Expand Down Expand Up @@ -108,6 +132,21 @@ aws lambda update-function-code --function-name <function_name> \
--zip-file fileb://./email_lambda.zip
```

#### Run Lambda with Localstack

```shell
make target/lambda/runnable/fn/bootstrap
echo '{"Records":[]}' \
| docker run \
-i \
-e DOCKER_LAMBDA_USE_STDIN=1 \
-e DYNAMO_TABLE="emails_local" \
-e QUEUE_URL="http://localhost:4566/000000000000/emails_local" \
--rm \
-v "${PWD}/target/lambda/runnable/fn":/var/task \
lambci/lambda:provided
```

### Deploy with AWS CDK

List the stacks available for deployment
Expand Down

0 comments on commit 78c2a6c

Please sign in to comment.