Building An AWS Serverless Infrastructure
I try to create an infrastructure for a serverless app.
Designing AWS Infrastructure:
The idea is a custom VPC which contains;
- 1 private subnet
- A lambda service that is located on a private subnet.
- An API Gateway that organizes communication with Lambda service.
- An S3 Bucket
- An S3 endpoint for VPC
An API Gateway can trigger the lambda function.
Lambda function can access S3.
S3 and Lambda function shouldn’t be accessible from outside.
Firstly, create a VPC.
Then create a private subnet for it.
Create a basic serverless function
We should add “AWSLambdaVPCAccessExecutionRole”, “AmazonS3FullAccess” policy to the role that used for serverless function creation.
We attach lambda function to VPC
We create an API Gateway trigger for it.
Then create a POST route for the lambda.
Now, it is ready to use:
When you view your lambda function, you can see the triggers. Then you can try it.
Let’s test the endpoint via console (**httpie)
➜ Desktop http POST https://ewfp7xvzn6.execute-api.eu-central-1.amazonaws.com/default/generate-coverHTTP/1.1 200 OK
Apigw-Requestid: LgEn8j3mliAEMLg=
Connection: keep-alive
Content-Length: 20
Content-Type: text/plain; charset=utf-8
Date: Fri, 24 Apr 2020 16:59:43 GMT"Hello from Lambda!"
Now, We should create an S3 and define an access point for VPC.
Then upload the zip file to S3. Because we will use S3 link to compile layer.