Lambda - URL Invoking

Task

Diagram

Diagram Ten GIF

File Structure

Steps

Configure the provider

  • Create a new file called provider.tf

  • configure the provider as below code

VPC Resource Deployment

We need to Create VPC Network with Public subnet for Developer accessing EC2 by SSH Connection,

So we need VPC, Subnet, Route Table, and finally Internet gateway

  1. Create a file called vpc.tf and put VPC, Route table, and internet gateway

  1. Create a file called subnet.tf

Security Group Resource Deployment

before we create EC2 Resource we need to configure who can access we should go with the least privilege access but for testing purpose we will use 0.0.0.0/0 All IPs can access not recommended at all.

  1. EC2 SSH Rules

  1. EFS Rules

EC2 Resource Deployment

We need to create EC2 that will Invoke Lambda By curl Lambda URL

we will use user_data to make sure curl is installed in our EC2

IAM Resource Deployment

We need to Create IAM Role for EC2 to Invoke Lambda using Curl, and we also need IAM Role for Lambda to access EFS Storage, so I will give Lambda EFSFullAccess policy to EFS,

  1. Create IAM Role For EC2

  1. Create IAM Role For Lambda

EFS Resource Deployment

What is Elastic File System?

EFS is AWS Fully managed service, EFS is a file storage service that's scalable and high availability ( multi AZ option), you can share EFS with multiple EC2 instances can simultaneously access the same file system, making it perfect for applications that require shared storage.

So we need to create EFS that point to EC2 Subnet

Lambda Resource Deployment

We need to create lambda that take ZIP Code who activate EFS mount storage in ec2, and create function URL so we can invoke lambda via CURL, Note: Lambda Depend on EFS Resource to be created first, and configure file system with mount path.

You can check whole Task in here ( Github arrow-up-right)

Working Examples

EC2 Policy Created
IAM Role Created
Network Created
EFS Created
EC2 Created
Lambda With Function URL Created
Invoke Lambda using URL Worked
EFS Mount Worked

Conclusion

In this task, I successfully learned how to:

  1. Create an EFS (Elastic File System) Environment:

    • I set up an EFS file system for use across multiple EC2 instances, ensuring they can access shared storage.

    • Configured security groups, VPC, and EFS mount targets to ensure proper communication between EC2 instances and the EFS system.

    • Used NFS for mounting the EFS file system on EC2 instances and ensured correct IAM roles and permissions for EC2 to interact with the EFS.

  2. Invoke Lambda Functions Using Function URL:

    • I set up an AWS Lambda function and invoked it via a Lambda Function URL, enabling communication with external systems or applications.

    • Integrated Lambda with EFS to allow the function to access shared storage, and configured necessary access points and IAM roles for security.

Through this task, I gained hands-on experience in configuring AWS EFS and Lambda, as well as securing resources with IAM roles and security groups. I also became more familiar with AWS networking concepts, including VPCs, subnets, and security group configuration

Last updated