【发布时间】:2019-05-13 07:15:22
【问题描述】:
我根据从我的自定义资源获取输出的条件(即True 或False)有条件地创建S3Bucket。我的堆栈模板看起来像这样
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"BucketName": {
"Type": "String",
"Description": "Name of the Bucket."
}
},
"Conditions" : {
"BucketExistsOutput" : {"Fn::Equals" : [{ "Fn::GetAtt" : [ "BucketExists", "Output" ]}, "False"]}
},
"Resources": {
"S3BucketARN": {
"Type" : "AWS::S3::Bucket",
"Condition" : "BucketExistsOutput",
"Properties" : {
"BucketName" : { "Ref" : "BucketName" }
}
},
"DeploymentLambdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "PermissionsToLogsAndS3",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"*"
]
}
]
}
}
]
}
},
"DeploymentLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Role": {
"Fn::GetAtt": [
"DeploymentLambdaRole",
"Arn"
]
},
"Handler": "bucketexists.handler",
"Runtime": "nodejs4.3",
"Code": {
"S3Bucket": "xxxx-xx",
"S3Key": "bucketcondition.zip"
}
}
},
"BucketExists": {
"Type": "Custom::BucketExists",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"DeploymentLambda",
"Arn"
]
},
"Bucket": {
"Ref": "BucketName"
}
}
}
},
"Outputs" : {
"BucketExistsValue" : {
"Description": "The Value of custom bucket lambda",
"Value" : { "Fn::GetAtt" : [ "BucketExists", "Output" ]}
}
}
}
这是抛出这样的错误
模板无效:模板格式错误:未解决的依赖关系 [桶存在]。无法在的条件块中引用资源 模板
这说明我无法在我的条件块中指向资源。
我该如何解决这种情况?他们有什么解决方法吗?
谢谢 任何帮助表示赞赏
【问题讨论】:
标签: amazon-web-services amazon-cloudformation