A developer is building a smart home application that processes real-time device state updates from thousands of smart hubs. The hubs publish state updates to an Amazon Kinesis Data Stream. An AWS Lambda function, configured with an Event Source Mapping, processes the stream in batches. The Lambda function needs to query an Amazon ElastiCache for Redis cluster located in a private VPC subnet to retrieve device owner metadata, and then send alert notifications to an external push notification gateway API.
The developer configures the Lambda function to run inside the same private VPC subnets. However, during testing, the Lambda function fails to connect to the external API, resulting in batch processing failures.
Which configuration should the developer implement to resolve the connectivity issue and process the stream efficiently?
- AKeep the Lambda function in the private subnets without a NAT Gateway, and increase the Lambda function execution timeout to the maximum limit of minutes to allow network connection retries to eventually succeed when the container is reused.
- Provision a NAT Gateway in a public VPC subnet, configure the route table of the private subnets to direct outbound traffic () to the NAT Gateway, and ensure the smart hubs write to the Kinesis stream using a high-entropy partition key, such as a unique device ID.Answer
- CModify the Lambda function's IAM trust policy to trust the VPC service (`vpc.amazonaws.com`), and configure the smart hubs to use a static string as the partition key to ensure all events are processed by a single shard in chronological order.
- DMove the Lambda function to a public VPC subnet with direct internet access, and configure the smart hubs to use a low-entropy partition key, such as the device manufacturer name, to reduce the complexity of the stream structure.