AWSTemplateFormatVersion: This specifies the version of the AWS CloudFormation template format used (2010-09-09 in this case).
Description: This provides a brief description of the template file.
Resources: This section defines the resources to be created in the CloudFormation stack.
LambdaRole: This is an AWS::IAM::Role resource to define the role for the Lambda function. It defines a role named “lambda-role” and specifies the policy for that role.
LambdaFunctionDemo: This is an AWS::Lambda::Function resource to create the Lambda function. It names the function “CfnLambdaDemo” and specifies other attributes such as handler, source code, runtime, memory size, timeout, and role.
Outputs: This section defines the output values of the CloudFormation template.
LambdaRoleArn: This is an output value to provide the ARN (Amazon Resource Name) of the LambdaRole.
LambdaFunctionName: This is an output value to provide the name of the Lambda function (LambdaFunctionDemo).
This template creates an IAM role and a Lambda function, and provides output values to use in subsequent processes or system configurations.
cd CloudFormation-series
cd day-1
lambda.yaml
file, which is the template for creating the Lambda Function.aws cloudformation create-stack \
--stack-name cfn-lambda-demo \
--template-body file://lambda.yaml \
--capabilities CAPABILITY_NAMED_IAM
Check the Resources section, which should contain LambdaFunctionDemo and LambdaRole.
Check the Output section.
Go to Lambda, where you will see that LambdaFunction has been created.
Go to the Lambda Function, select Test, and perform Test event.
Create a Create new event and Event name.
After testing, you will see the Log output.