I have a problem in cloud formation. Error when using Fn::Join with a parameter

会有一股神秘感。 提交于 2020-03-05 04:10:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!