Home > other >  Data transfer costs when one lambda invokes another lambda
Data transfer costs when one lambda invokes another lambda

Time:07-09

I have two lambdas. LambdaA is the parent lambda that invokes LambdaB in parallel using the Event InvocationType (boto3). In every invocation, LambdaA sends a payload of 5MB to LambdaB. Both the lambdas are in the same VPC and in the same two private subnets (and same security group).

Now, assuming that LambdaA invokes LambdaB 5000 times in parallel for further invocation, a total payload of 25GB would be transferred between LambdaA and LambdaB.

  1. I am trying to find out if I would be charged for the 50GB of data transfer as a data transfer cost, given that the data transfer is within the same VNet and the same two private subnets (and same security group).

  2. Would I also be charged if there are in the same VPC and in the same private subnet (only one and same security group)?

CodePudding user response:

When an AWS Lambda function invokes another AWS Lambda function, it would be sending traffic to the endpoint of the AWS Lambda service (not to the other Lambda function itself). Since your first Lambda function is connected to a VPC and the AWS Lambda service endpoint is on the Internet, the request would need to exit the VPC to access the Internet.

From EC2 On-Demand Instance Pricing – Amazon Web Services:

Data transferred “in” to and “out” from public or Elastic IPv4 address is charged at $0.01/GB in each direction.

However, if your first Lambda function was not connected to a VPC, then there would be no such charge since the Lambda function would be directly connected to the Internet. Typically, you should only connect an AWS Lambda function to a VPC if it specifically needs to access resources in that VPC (eg an Amazon RDS database).

Alternatively, you could use a VPC Endpoint to directly connect to to the AWS Lambda service. From Configuring interface VPC endpoints for Lambda - AWS Lambda:

If you use Amazon Virtual Private Cloud (Amazon VPC) to host your AWS resources, you can establish a connection between your VPC and Lambda. You can use this connection to invoke your Lambda function without crossing the public internet.

This would allow your Lambda function to connect to the VPC, but also connect to the AWS Lambda service without 'exiting' the VPC, thereby avoiding the 1c/GB charge.

The main thing to realise is that the two Lambda functions are not directly communicating. Rather, the communication is to the AWS Lambda service, which is then responsible for provisioning and invoking the second Lambda function.

CodePudding user response:

Yes, you will be charged the EC2 AZ to AZ ingress and egress cost.

If the data was downloaded via S3 there would be no cost.

  • Related