Simple architecture for apis use case. Below the components involved.
Component working as interface towards the outer world and functioning as proxy to dispatch request against the lambdas correctly configured behind and attached to it via resources, method and integration
- apiProjects lambda (Readme can be found here)
- apiComments lambda (Readme can be found here)
- apiIssues lambda (Readme can be found here)
This lambdas are meant to work as REST endpoints serving 3 different entities, respectively projects, comments and issues
Fake database emulated retrieving data from a json file (path: data/db.json) having in it the entities mentioned above presented as array of objects
Here a simple diagram to give the idea of the infrastructure:
In order to run this example you need:
- An AWS account (with AWS cli installed and configured)
- Terraform (0.11+)
One approach can be for instance once your aws credentials are created, export this var in your .bash_profile file:
export AWS_ACCESS_KEY_ID=XXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXX
export AWS_DEFAULT_REGION=eu-west-1In order to deploy this solution below all the task we can perform via make file:
make package # create the lambda packages under the folder ./build and respectively `api-projects.zip`, `api-comments.zip`, `api-issues.zip`make create_bucket # create your create_bucket on aws s3 where to deploy your lambda's artifact codemake deploy_artifacts # deploy the lambda packages against bucket s3://artifact-lamdasmake clean # clean up your build foldermake apply # perform terraform apply so deploying all the infrastructuremake destroy # perform terraform destroy and then remove all the infrastructureAfter the deployment you will see as output AWS Api Gateway the base invoke url:
curl https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/stage1/projectscurl https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/stage1/projects/1/commentscurl https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/stage1/commentscurl https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/stage1/issues
