2025-01-10Hünkar Döner
Serverless Integration with EKS (Lambda + EKS)
ServerlessLambdaEKSEventBridgeIntegration
S
Serverless Integration with EKS (Lambda + EKS)
Containers and Serverless functions are not rivals, but complementary. In many modern architectures, long-running services run on Amazon EKS, while event-driven short tasks run on AWS Lambda.
Use Cases
- File Processing: When a file is uploaded to your application on EKS, it is saved to S3. The S3 event triggers Lambda, Lambda resizes the image and reports the result to EKS.
- Webhook Processing: You can receive webhooks from the outside world with API Gateway + Lambda, process them, and put the result in an SQS queue for EKS to consume.
Calling Lambda from EKS
To call Lambda from inside your EKS pod:
- IRSA: Assign an IAM role with
lambda:InvokeFunctionpermission to your pod. - AWS SDK: Call the function using AWS SDK inside your application.
import boto3
client = boto3.client('lambda')
response = client.invoke(FunctionName='my-function', Payload='...')
Accessing EKS from Lambda
If your Lambda function needs to access a service inside EKS (e.g., Redis or a private API):
- VPC Config: Put Lambda in the same VPC and Private Subnets as EKS.
- Security Group: Grant access permission to Lambda's security group from the EKS security group.
This hybrid structure is a pattern we frequently use for cost and performance optimization in AWS Consultancy projects.