Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

amazon web services - Using fn::split in Serverless yaml configuration not working

I'm using serverless framework to deploy an API on AWS. I have the following in my serverless.yml file:

custom:
  vpcSettings:
    private:
      securityGroupIds:
        private:
          fn::split:
            delimiter: ','
            value: ${env:VPC_SG_ID}

VPC_SG_ID contains the following string: sg-1111111111,sg-222222222,sg-3333333333

However, when deploying the application, I get the following error: An error occurred: MyLambdaFunction - Value of property SecurityGroupIds must be of type List of String.

If I hardcode the SGs list, it's working without any issue:

custom:
  vpcSettings:
    private:
      securityGroupIds:
        private:
          - "sg-1111111111"
          - "sg-2222222222"
          - "sg-3333333333"

Why the fn::split function is not returning a list of strings?

Edit:

The following configuration results in the same error

custom:
  vpcSettings:
    private:
      securityGroupIds:
        private:
          Fn::Split:
            - ','
            - ${env:VPC_SG_ID}
question from:https://stackoverflow.com/questions/65600660/using-fnsplit-in-serverless-yaml-configuration-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If Security group is added as Input parameter to template

Parameters:
  VPCSGID:
    Type: String
    Description: Comma separated Security Groups

Security Groups can be split with !Split as

SecurityGroupIds: !Split [",", !Ref VPCSGID]

can be split with Fn:Split as

SecurityGroupIds: { "Fn::Split": [",", !Ref VPCSGID] }

Parameter to sam deploy can be passed as

sam deploy --parameter-overrides 'ParameterKey=VPCSGID,ParameterValue=sg-011111,sg-222222'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...