如何解决AWS 中此 Cloudformation 模板中的内在函数 !Ref 的错误是什么?
最近我开始探索 YAML 格式的 AWS CloudFormation。我收到错误消息:
YAML 代码说明如下:-
AWstemplateFormatVersion: 2010-09-09
Resources:
DevEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-04aa88aebb9fefd83
Type: t2.micro
KeyName: Newkey
SecurityGroups:
- default
- !Ref SSHSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Group_For_CloudFormation
SecurityGroupIngress:
- Ipprotocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
解决方法
你能检查一下这个片段是否适合你吗?
Resources:
DevEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-04aa88aebb9fefd83
InstanceType: t2.micro
KeyName: Newkey
SecurityGroups:
- default
- !Ref SSHSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Group_For_CloudFormation
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
,
所以正确的代码如下:-
AWSTemplateFormatVersion: 2010-09-09
Resources:
DevEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-04aa88aebb9fefd83
InstanceType: t2.micro
KeyName: Newkey
SecurityGroups:
- default
- !Ref SSHSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SMy Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
,
错误是由于资源 SSHSecurityGroup
上缺少缩进,在 YAML 中您需要小心缩进。这使得 Cloudformation 不将该元素作为资源,因为它处于同一缩进级别。
这应该有效:
AWSTemplateFormatVersion: 2010-09-09
Resources:
DevEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-04aa88aebb9fefd83
InstanceType: t2.micro
KeyName: Newkey
SecurityGroups:
- default
- !Ref SSHSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Group_For_CloudFormation
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。