Cloudformation 转换无效 Yaml/JSON
Cloudformation Transform invalid Yaml/JSON
我有 2 个模板如下。我想问的是如何在Transform中使用Sub
和其他变量?
当我添加 UserData 时,出现以下错误。这大约是 Sub
。我怎样才能根据变换改变它?
转换 AWS::Include 失败:指定的 S3 对象的内容应该有效 Yaml/JSON。用户请求回滚。
main.yaml
Parameters:
VpcId:
Type: 'AWS::EC2::VPC::Id'
Subnets:
Type: 'List<AWS::EC2::Subnet::Id>'
InstanceType:
Type: String
Default: c5.large
AllowedValues:
- c5.large
- c5.xlarge
Resources:
Instance:
Fn::Transform:
Name: AWS::Include
Parameters:
Location:
Fn::Sub: s3://test-bucket/instance.yaml
instance.yaml
Type: 'AWS::EC2::Instance'
Properties:
KeyName: test
ImageId: ami-0015a39e4b7c0966f
InstanceType:
Ref: InstanceType
SubnetId:
Fn::Select: [ 0, Ref: Subnets ]
SecurityGroupIds:
- Fn::GetAtt: [ Sec, GroupId ]
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
您不能使用 !Sub
。应该是 Fn::Sub:
:
Type: 'AWS::EC2::Instance'
Properties:
KeyName: test
ImageId: ami-0015a39e4b7c0966f
InstanceType:
Ref: InstanceType
SubnetId:
Fn::Select: [ 0, Ref: Subnets ]
SecurityGroupIds:
- Fn::GetAtt: [ Sec, GroupId ]
UserData:
Fn::Base64:
Fn::Sub: |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
我有 2 个模板如下。我想问的是如何在Transform中使用Sub
和其他变量?
当我添加 UserData 时,出现以下错误。这大约是 Sub
。我怎样才能根据变换改变它?
转换 AWS::Include 失败:指定的 S3 对象的内容应该有效 Yaml/JSON。用户请求回滚。
main.yaml
Parameters:
VpcId:
Type: 'AWS::EC2::VPC::Id'
Subnets:
Type: 'List<AWS::EC2::Subnet::Id>'
InstanceType:
Type: String
Default: c5.large
AllowedValues:
- c5.large
- c5.xlarge
Resources:
Instance:
Fn::Transform:
Name: AWS::Include
Parameters:
Location:
Fn::Sub: s3://test-bucket/instance.yaml
instance.yaml
Type: 'AWS::EC2::Instance'
Properties:
KeyName: test
ImageId: ami-0015a39e4b7c0966f
InstanceType:
Ref: InstanceType
SubnetId:
Fn::Select: [ 0, Ref: Subnets ]
SecurityGroupIds:
- Fn::GetAtt: [ Sec, GroupId ]
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}
您不能使用 !Sub
。应该是 Fn::Sub:
:
Type: 'AWS::EC2::Instance'
Properties:
KeyName: test
ImageId: ami-0015a39e4b7c0966f
InstanceType:
Ref: InstanceType
SubnetId:
Fn::Select: [ 0, Ref: Subnets ]
SecurityGroupIds:
- Fn::GetAtt: [ Sec, GroupId ]
UserData:
Fn::Base64:
Fn::Sub: |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource LaunchConfig --configsets wordpress_install --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerGroup --region ${AWS::Region}