Building An AWS Serverless Infrastructure

Mustafa İleri
3 min readApr 24, 2020

--

API Gateway — Lambda Layered Service — S3 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.

Create a custom VPC

Then create a private subnet for it.

Create a private subnet

Create a basic serverless function

Create a serverless function

We should add “AWSLambdaVPCAccessExecutionRole”, “AmazonS3FullAccess” policy to the role that used for serverless function creation.

Roles for serverless

We attach lambda function to VPC

Attach lambda function to a VPC

We create an API Gateway trigger for it.

Create a trigger for lambda function

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.

S3 endpoint for VPC

Then upload the zip file to S3. Because we will use S3 link to compile layer.

--

--

Mustafa İleri
Mustafa İleri

Written by Mustafa İleri

Tech Lead / Architect, Data Engineer, loves #python #symfony #django

No responses yet