2019-08-27 16:10:26 +00:00
|
|
|
Deploy AWS resources in localstack with Terraform
|
|
|
|
=================================================
|
|
|
|
|
2019-09-03 12:57:25 +00:00
|
|
|
[Detailed tutorial here.](https://baptiste.bouchereau.pro/tutorial/deploy-localstack-resources-with-terraform/)
|
|
|
|
|
2019-08-27 16:10:26 +00:00
|
|
|
An example on how to use Terraform to deploy localstack resources that mock AWS services. The following instructions focus on how to deploy:
|
|
|
|
* a dynamodb table
|
|
|
|
* a lambda reading data and putting data to this table
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
Run
|
|
|
|
|
|
|
|
```bash
|
2020-02-10 22:10:42 +00:00
|
|
|
git clone https://github.com/Ovski4/tutorials.git
|
|
|
|
cd localstack-part-2
|
2019-08-27 16:14:47 +00:00
|
|
|
docker network create localstack-tutorial
|
2019-08-27 16:10:26 +00:00
|
|
|
docker-compose up -d
|
|
|
|
docker-compose logs -f localstack
|
|
|
|
```
|
|
|
|
|
|
|
|
Create the lambda:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd lambda
|
|
|
|
zip -r ../lambda.zip .
|
|
|
|
cd ..
|
|
|
|
```
|
|
|
|
|
|
|
|
Wait for set up to be done, then apply the Terraform configuration:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
terraform init
|
|
|
|
terraform plan
|
|
|
|
terraform apply --auto-approve
|
|
|
|
```
|
|
|
|
|
|
|
|
Invoke the lambda multiple times and scan the table to see new items and their counters being incremented:
|
|
|
|
|
2019-08-27 16:14:47 +00:00
|
|
|
```bash
|
2019-08-27 16:10:26 +00:00
|
|
|
aws lambda invoke --function-name counter --endpoint-url=http://localhost:4574 --payload '{"id": "test"}' output.txt
|
|
|
|
aws dynamodb scan --endpoint-url http://localhost:4569 --table-name table_1
|
|
|
|
|
|
|
|
aws lambda invoke --function-name counter --endpoint-url=http://localhost:4574 --payload '{"id": "test2"}' output.txt
|
|
|
|
aws dynamodb scan --endpoint-url http://localhost:4569 --table-name table_1
|
2020-02-24 18:27:37 +00:00
|
|
|
```
|