securityGroupIds but where to get the ID from?


#1

Hi,

apihelloworld:
    handler: hello.world
    vpc:
      securityGroupIds:
        - OkLambdaSG
      subnetIds:
        - OkaydocsPublicSubnet
    events:
      - http:
          path: hello
          method: get
          cors: true

i am creating the whole Network Stack (VPC, SecGroups, Routes, etc.) with serverless via Cloudformation Resources section. Now i want to apply the VPC subnet and securityGroups to my lambdas. But with horror i see that you need to supply the Security Group ID which i cant know at this point (it will be created by AWS right?). I only have the internal REF name as seen in the code.

Can it be that one cant make this really dynamic?

thanks
marc


#2

You can use Fn::GetAtt to retrieve the GroupId for a security ground. Something like

apihelloworld:
    handler: hello.world
    vpc:
      securityGroupIds:
        - { "Fn::GetArr", [ "OkLambdaSG", "GroupId" ] }
      subnetIds:
        - OkaydocsPublicSubnet
    events:
      - http:
          path: hello
          method: get
          cors: true