This pattern explains how to deploy a SAM application that includes an API Gateway, Lambda Function and Amazon EFS.
Learn more about this pattern at: https://serverlessland.com/patterns?services=efs.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS Serverless Application Model (AWS SAM) installed
The following diagram illustrates the solution architecture:
- Create a new project directory and a new serverless application in AWS SAM using the following command:
$ mkdir efs-lambda-project $ cd efs-lambda-project $ sam init
- Choose Custom Template Location (Choice: 2) as the template source, and provide the following GitHub template location:
https://github.com/debnsuma/apigw-lambda-efs.git
- From the command line, build the application:
$ sam build --use-container
- Deploy the application
Take a note of the HTTP API Gateway endpoint \
$ sam deploy --guided
Once the application is deployed, you can test by making some lambda invocation which will write, read and delete data from the Amazon EFS storage:
$ curl https://<HTTP API Gateway Endpoint>
null
$ curl -X POST -H "Content-Type: text/plain" -d 'Hello from EFS!' https://<HTTP API Gateway Endpoint>
Hello from EFS!
$ curl -X POST -H "Content-Type: text/plain" -d 'Hello again :)' https://<HTTP API Gateway Endpoint>
Hello from EFS!
Hello again :)
$ curl https://<HTTP API Gateway Endpoint>
Hello from EFS!
Hello again :)
$ curl -X DELETE https://<HTTP API Gateway Endpoint>
Messages deleted.
$ curl https://<HTTP API Gateway Endpoint>
null