question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS Lambda: Support Fn::Split in `vpc.securityGroupIds` and `vpc.subnetIds` configurations

See original GitHub issue

sls produces correct CloudFormation, but issues a configuration warning. This has been discussed and fixed in issue #8282 but I guess Split function slipped the radar.

serverless.yml
service: hello-world
frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs12.x
  vpc:
    subnetIds: !Split
      - ','
      - "sn1,sn2"
    securityGroupIds: !Split
      - ','
      - "sg1,sg2"

functions:
  hello:
    handler: handler.hello
output
✔ ~/src/testing/serverless-fw/hello-world ➭ sls package
Serverless: Configuration warning:
Serverless:   at 'provider.vpc.securityGroupIds': should be array
Serverless:   at 'provider.vpc.subnetIds': should be array
Serverless:
Serverless: Learn more about configuration validation here: http://slss.io/configuration-validation
Serverless:
Serverless: Packaging service...
Serverless: Excluding development dependencies...

Installed version

Framework Core: 2.11.1 (local)
Plugin: 4.1.2
SDK: 2.3.2
Components: 3.3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
takedacommented, Dec 5, 2020

@vmj this is just a nitpick, because I seen this everywhere, you wrote:

    subnetIds:
      Fn::Split: [',', "sn1,sn2"]
    securityGroupIds:
      Fn::Split:
        - ','
        - "sg1,sg2"

it’s probably better to write it like this:

    subnetIds: {"Fn::Split": [",", "sn1,sn2"]}
    securityGroupIds: {"Fn::Split": [",", "sg1,sg2"]}

I doubt this will solve the original issue (I think it will require serverless code change), but it makes easier to read when the long form is used.

@medikoo to answer your question here’s what I’m doing in my configuration:

    vpc:
      subnetIds: !Split [",", !ImportValue PrivateSubnets]
      securityGroupIds:
      - !ImportValue DefaultSecurityGroup

Ideally I think all functions should be supported. I also think this will be a problem for validation. For example if I use !Ref it typically is a string, but I believe it could also be an array if I would use a parameter of an array type (it doesn’t look to me like it makes sense to use parameters, but maybe there actually is a use case where it would be beneficial)

3reactions
medikoocommented, Sep 28, 2021

@younghoonk17 in terms of Fn::GetAtt, it is supported, but on item level not array level, so following will work:

vpc:
  subnetIds: 
    - "Fn::GetAtt":
      - CustomResourcesLookup
      - ResourceId
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring a Lambda function to access resources in a VPC
You can configure a Lambda function to connect to private subnets in a virtual private cloud (VPC) in your AWS account. Use Amazon...
Read more >
Lambda::Function VpcConfig - AWS CloudFormation
When you connect a function to a VPC, Lambda creates an elastic network interface for each combination of security group and subnet in...
Read more >
Using AWS Lambda IAM condition keys for VPC settings
The three new condition keys for VPC settings are lambda:VpcIds, lambda:SubnetIds, and lambda:SecurityGroupIds. The keys allow you to ensure ...
Read more >
VpcConfig - AWS Lambda
A list of VPC security group IDs. Type: Array of strings. Array Members: Maximum number of 5 items. Required: No. SubnetIds. A list...
Read more >
AWS::Lambda::Function VpcConfig - AWS CloudFormation
A list of VPC security group IDs. Required: No. Type: List of String. Maximum: 5. Update requires: No interruption. SubnetIds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found