here is my template
{
"AWSTemplateFormatVersion":"2010-09-09",
"Resources":{
"lambdafunction":{
"Type":"AWS::Lambda::Function",
"Properties":{
"Handler":"index.handler",
"Role":{
"Fn::GetAtt":[
"RootRole",
"Arn"
]
},
"Code":{
"S3Bucket":"{s3_bucket_name}",
"S3Key":"lambda-zip"
},
"Runtime":"java8",
"Timeout":"25"
}
},
"RootRole":{
"Type":"AWS::IAM::Role",
"Properties":{
"AssumeRolePolicyDocument":{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Principal":{
"Service":[
"ec2.amazonaws.com"
]
},
"Action":[
"sts:AssumeRole"
]
}
]
},
"Path":"/",
"Policies":[
{
"PolicyName":"root",
"PolicyDocument":{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":"*",
"Resource":"*"
}
]
}
}
]
}
}
}
}
The name of the lambda function after the stack creation is lambda-lambdafunction-18SJKJ5Q40AKZ The name of IAM role is lambda-RootRole-12S8E9CA0EOVM
The template does not seem to have a way to define the lambda function name http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html. And I am not sure why random characters are appended at the end.
Attach the IAM policy to an IAM roleNavigate to the IAM console and choose Roles in the navigation pane. Choose Create role. Choose AWS service and then choose Lambda. Choose Next: Permissions.
The AWS::Lambda::Function resource creates a Lambda function. To create a function, you need a deployment package and an execution role. The deployment package is a . zip file archive or container image that contains your function code.
We'll need to create a role for the CloudFormation service to assume. That role will need a policy with the s3:CreateBucket permission. It also will need something called an assume role policy document which defines the trust relationship so that the CloudFormation service can assume this role.
A service role is an AWS Identity and Access Management (IAM) role that allows AWS CloudFormation to make calls to resources in a stack on your behalf.
Update: both AWS::IAM::Role and AWS::Lambda::Function now support custom names.
By default, CloudFormation generates a unique ID for resource names. This makes sense because it allows you to re-use the template again and again.
Some resource types, but not all, support custom names. Examples that do support custom names are AWS::DynamoDB::Table ('TableName') and AWS::S3::Bucket ('BucketName').
For more info, and a complete list of resources that support custom names, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With