gpt4 book ai didi

amazon-web-services - Cloudformation 转换无效的 Yaml/JSON

转载 作者:行者123 更新时间:2023-12-03 07:22:52 24 4
gpt4 key购买 nike

我有如下 2 个模板。我想问的是如何在Transform中使用Sub等变量?

当我添加 UserData 时,出现以下错误。这是关于 Sub 的。如何根据变换来改变它?

转换 AWS::Include 失败:指定的 S3 对象的内容应该是有效的 Yaml/JSON。用户请求回滚。

ma​​in.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}

此限制已涵盖 in the documentation :

We don't currently support using shorthand notations for YAMLsnippets.

关于amazon-web-services - Cloudformation 转换无效的 Yaml/JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70636592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com