|
|
Installing AWS infrastructure through Terraform scripts
|
|
|
==============================================================================
|
|
|
|
|
|
This page explains how to set up the expected infrastructure awaited to implement the JSON API.
|
|
|
The installation is based on Terraform (https://www.terraform.io/)
|
|
|
|
|
|
It expects that both AWS CLI and Terraform have been previously installed and set up correctly.
|
|
|
The AWS Credentials should also have been set up
|
|
|
|
|
|
How it works
|
|
|
------------------------------------------------------------------------------
|
|
|
AWS JSON API server relies on 3 main components, plus the needed IAM roles :
|
|
|
- A DynamoDB table manipuling all serialized objects
|
|
|
- A lambda function in charge of the translation from JSON API format to dynamoDB objects and managing the relationships and the optional parameters provided in the request
|
|
|
- An API Gateway configured to received the REST HTTP requests and proxying the Lambda
|
|
|
|
|
|
This infrastructure will just be completed by two S3 buckets :
|
|
|
* The first one being used to store the lambda function code,
|
|
|
* The second one provisioned to later store the static part of the web site.
|
|
|
|
|
|
Several Terraform files are available, each one creating the needed component and their relationships with each other.
|
|
|
|
|
|
Installation
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
The lambda code needs to be stored in a S3 bucket before running the Terraform scripts.
|
|
|
The script is available in the cloud/lambda directory of this project.
|
|
|
The following operations need to be performed (adapting the region you are using):
|
|
|
|
|
|
```
|
|
|
cp ../lambda/lambda-jsonapi.js .
|
|
|
zip lambda-jsonapi.zip lambda-jsonapi.js
|
|
|
aws s3api create-bucket --bucket=lambda-jsonapi-code-bucket --region=us-east-1
|
|
|
aws s3 cp lambda-jsonapi.zip s3://lambda-jsonapi-code-bucket/v1.0.0/lambda-jsonapi.zip
|
|
|
```
|
|
|
One this is done, simply run the terraform script :
|
|
|
```
|
|
|
terraform apply -var bucket_name=<bucket name for static web site>
|
|
|
```
|
|
|
For a strange reason I don't understand, the first time you run the terraform command, the mapping for the integration response fails. You have to run the command again to have your complete setup. |
|
|
\ No newline at end of file |