当AWS CloudFormation堆栈中的Lambda函数更新失败时,可能是由于以下原因导致的:
Lambda函数的IAM角色未被更新。
Lambda函数的代码未被正确更新。
AWS CloudFormation堆栈中的一些参数与Lambda函数不兼容。
以下是解决方案:
示例代码:
"LambdaRole": { "Type": "AWS::IAM::Role", "Properties": { "RoleName": "lambda-execution-role", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ] } }
示例代码:
"LambdaFunction": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "my-bucket", "S3Key": "my-key.zip" }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "LambdaRole", "Arn" ] }, "Runtime": "python3.6", "Environment": { "Variables": { "MY_VARIABLE": "my-value" } } } }
示例代码:
"StackParameters": { "Type": "AWS::CloudFormation::Stack", "Properties": { "TemplateURL": "https://s3.amazonaws.com/my-bucket/my-template.yaml", "Parameters": { "FunctionName": { "Ref": "LambdaFunctionName" } } } }