AWS Day 48: Automating Infrastructure Deployment with AWS CloudFormation

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops
Continuing my KodeKloud 100 Days of Cloud journey, Day 48 focused on using AWS CloudFormation to automate Lambda deployment.
Instead of creating the Lambda function and IAM role manually from the AWS Console, I defined the infrastructure as code in a CloudFormation template. This makes the deployment repeatable, consistent, and easier to manage.
What I Built
For this lab, I created:
CloudFormation stack:
xfusion-lambda-appLambda function:
xfusion-lambdaIAM role:
lambda_execution_roleRuntime: Python 3.12
Lambda response status code:
200Response body:
Welcome to KKE AWS Labs!
Step 1: Create the CloudFormation Template
I created the template on the AWS client host:
/root/xfusion-lambda.yml
The template defines both the IAM role and Lambda function, so CloudFormation can create the required resources automatically.
One important part is the Lambda execution role:
RoleName: lambda_execution_role
The role uses the AWS managed policy:
AWSLambdaBasicExecutionRole
which allows Lambda to write its execution logs to CloudWatch.
Step 2: Configure the Lambda Function
The Lambda function was configured with:
FunctionName: xfusion-lambda
Runtime: python3.12
Handler: index.lambda_handler
The function returns a successful HTTP-style response:
return {
"statusCode": 200,
"body": "Welcome to KKE AWS Labs!"
}
This satisfies the requirement for both the 200 status code and the expected response body.
Step 3: Deploy the CloudFormation Stack
After creating the YAML template, I deployed it using AWS CLI:
aws cloudformation create-stack --stack-name xfusion-lambda-app --template-body file:///root/xfusion-lambda.yml --capabilities CAPABILITY_NAMED_IAM
The CAPABILITY_NAMED_IAM option is required because the template creates a named IAM role.
CloudFormation then handled the creation of the IAM role and Lambda function.
Step 4: Verify the Lambda Function
After the stack was created successfully, I invoked the Lambda function:
aws lambda invoke \
--function-name xfusion-lambda \
--payload '{}' \
response.json
The invocation returned:
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
This confirmed that the Lambda function was successfully deployed and executed.
What I Learned
The main takeaway from this lab was how AWS CloudFormation turns infrastructure into code.
Conclusion
AWS Day 48 was a practical introduction to Infrastructure as Code with AWS CloudFormation.
Creating the Lambda function through CloudFormation helped me understand how AWS resources can be defined, deployed, and managed without relying entirely on the AWS Console.
Another step completed in my AWS, Cloud, and DevOps learning journey.




