Skip to content

Possible to reference a Security Group being created? #44

@corydorning53

Description

@corydorning53

In my serverless.yml I create the following security group in the resources section:

resources:
  Resources:
      MySecurityGroup:
        Type: AWS::EC2::SecurityGroup
        Properties:
          GroupDescription: Allow all outbound traffic, no inbound for Lambdas
          SecurityGroupEgress:
            - IpProtocol: tcp
              FromPort: 443
              ToPort: 443
              CidrIp: 0.0.0.0/0
          VpcId: ${self:custom.${self:provider.stage}.vpcId}

Then in my functions I reference it as:

functions:
  mylambda:
    handler: api/my.lambda
    runtime: nodejs14.x
    vpc:
      securityGroupIds:
        - Ref: MySecurityGroup

This has the side effect of giving the following configuration warning, even though its not really an issue, because I reference the subnets in the custom.vpcDiscovery:

Serverless: Configuration warning:
Serverless:   at 'functions.myLambda.vpc': should have required property 'subnetIds'

So I was wondering if I could remove the vpc.securityGroupIds altogether and just reference MySecurityGroup in the plugin config:

  vpcDiscovery:
    vpcName: ${self:custom.tk.vpc}
    subnets:
      - tagKey: Name
        tagValues:
          - app_sn_0
          - app_sn_1
          - app_sn_2
    securityGroups:
      - Ref: MySecurityGroup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions