Will having EC2/ECS/Fargate in the same availability zone as Lambda decrease latency?

0

I've been thinking about this article that mentions Availability Zone Affinity as a means to improve performance and reduce costs: https://aws.amazon.com/blogs/architecture/improving-performance-and-reducing-cost-using-availability-zone-affinity

If compute resources are in the same availability zone as a Lambda function, will that decrease latency?

asked 2 years ago1135 views
3 Answers
1
Accepted Answer

Yes. Availability zones are close enough to each other to allow for synchronous replication of data; but the facilities within an availability zone are even closer. All other things being equal, less distance equals less latency.

profile pictureAWS
EXPERT
answered 2 years ago
  • Thanks! Do you know if the Lambda Service API is also going to process the function within the availability zone? Like does it operate in the same availability zone as where the Lambda runtime environment is operating?

  • Lambda is a "regional" services which means that it runs across multiple availability zones. In general that means that you don't get to select which AZ the Lambda function is actually executing in.

1

Yes, but your Lambda Functions do not run within your VPC, they execute within the Lambda services account. Connectivity to your VPC is established by Configuring a Lambda function to access resources in a VPC. This creates an ENI within your defined Availability Zones that the Lambda Function utilizes to reach VPC resources:

Enter image description here

A Lambda function always runs inside a VPC owned by the Lambda service. Lambda applies network access and security rules to this VPC and Lambda maintains and monitors the VPC automatically. If your Lambda function needs to access the resources in your account VPC, configure the function to access the VPC. Lambda provides managed resources named Hyperplane ENIs, which your Lambda function uses to connect from the Lambda VPC to an ENI (Elastic network interface) in your account VPC.

from VPC networking for Lambda

There is no configuration item for specifying which Availability Zone in the Lambda service's VPC to use, and the Lambda service will run your Functions across Availability Zones for resiliency, so even if you can determine that, on one invocation, a Function ran in a particular AZ, it may not on the next run.

This article has a good description of how Lambda Function networking works, both before and after enhancements made in 2020.

If you have a workload that must have compute deployed together for the lowest latency, then with EC2 you can use placement groups to define how close (or far apart) to spread the instances; with ECS you can similarly define task placement, but you'll need to align EC2 and ECS configurations if your EC2 and ECS must be in the same AZ for certain traffic patterns.

profile pictureAWS
answered 2 years ago
  • Thanks for the insightful response. I remember reading about Lambda running in a VPC owned by the Lambda service but seemed to have forgotten. Unfortunately, the goal is to reduce latency between Fargate and Lambda so I cannot use something like placement groups.

  • I've noticed that while placing a Lambda function in a VPC with only 1 subnet that this message is displayed:

    "We recommend that you choose at least 2 subnets for Lambda to run your functions in high availability mode."

    So if a Lambda function is placed in one AZ does this mean that Lambda runs the function only in that AZ? If so, this would help me accomplish targeting the right AZ from Fargate.

0

If you implement API client-side service discovery, which might add some milliseconds, yes, but allow you to implement a very simple logic to always favor same-AZ traffic and only if not an option, fallback onto the next one. Wanting to do same-AZ traffic only is obviously not optimal if that AZ were to become unavailable. For me, the major benefit of the same AZ traffic is no traffic costs within that AZ.

profile picture
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions