Lambda function to remove a running POD from EKS cluster and allow the matching deployment to run it again, updating it.
Thia allows microservice updating after a codepipeline run.
It uses the awscli
because the get-token
command is not available in boto3
library.
- Codepipeline user parameters: you must insert the deployment name in the user parameters field for this to work
- Lambda Layer
- ENV variables
- Permissions: must have the AWSLambdaBasicExecutionRole, AWSCodePipelineCustomActionAccess policies and of course be able to access the EKS cluster to read cluster info. Pay attention, use the right VPC/Subnet/SG for the lambda or you won't be able to access the cluster
- Lambda configuration: at least 256MB and 5 minutes timeout
This script requires a lambda layer containing two python packages, to build the layer you can do the following
pip3 install awscli kubernetes -t ./python --no-cache
zip -r lambda-layer.zip python/
Then upload the zip file on AWS as a lambda layer. The runtime it was tested on is Python 3.9 on x86_x64 architecture.
Required variables are:
- CLUSTER_NAME: the cluster name on EKS
- NAMESPACE: the namespace where the deployment is located