问题
I am trying to create one Security Group and calling other security group from parameters using cloudformation. I used this as a resource however I get the following error message from cloudfromation
Template validation error: Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.
AWSTemplateFormatVersion : 2010-09-09
Description: "simple web layer"
Parameters:
Securitygroupid:
Description: enter sc
Type: List<AWS::EC2::SecurityGroup::Id>
NoEcho: false
Default: sg-05323df39f12d8034
Resources:
Lpsecurity:
Type: AWS::EC2::SecurityGroup
Properties:
Securitygroupid:
Description: enter sc
Type: List<AWS::EC2::SecurityGroup::Id
NoEcho: false
Default: sg-05323df39f12d8034
VpcId: !Ref Vpc
GroupDescription: Sample target security group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: !Ref Securitycab
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !Ref Securitycab
MyEC2Instance1:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref ImageId
InstanceType: t2.micro
SubnetId: !Select [ 0, !Ref Subnets ]
SecurityGroupIds: !Join [ ",", [ !Ref Securitygroupid, !Ref Lpsecurity ]]
What am I doing wrong here?
回答1:
I found solution.
SecurityGroupIds: !Split
- ","
- !Sub
- "${idList},${Lpsecurity}"
- idList: !Join [",",!Ref "SecurityGroup"]
回答2:
The SecurityGroupIds should be a list type.
Try the following
Resources:
Lpsecurity:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: !Ref Vpc
GroupDescription: Sample target security group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: !Ref Securitycab
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !Ref Securitycab
MyEC2Instance1:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref ImageId
InstanceType: t2.micro
SubnetId: !Select [ 0, !Ref Subnets ]
SecurityGroupIds:
- !Ref Securitygroup
- !GetAtt Lpsecurity.GroupId
来源:https://stackoverflow.com/questions/60135836/i-have-a-problem-in-cloud-formation-error-when-using-fnjoin-with-a-parameter