0
votes

There are two vpcs(default that comes when an account is created and another one created by me) in my aws account.i wanted to deploy my lambda function in custom created vpc rather than in default vpc

  vpc:
    subnetIds:
      - subnet-123456
      - subnet-452345
    securityGroupIds:
      - sg-ff555144
      - sg-edfe5566

above creates the lambda function in default vpc

serverless docs doesn't contain the way of specifying custom vpc in serverless.yml

1

1 Answers

1
votes

Firstly, you don't need to deploy lambda into a specific VPC, you only need to do it if you need Lambda functions to specifically access resources that are only available within your VPC. If you don't have a use case for this, you can just remove the VpcConfig from your lambda resource.

Secondly, if you do need it to be inside a specific then in Cloudformation you're not linking it to a VPC, instead you are linking it to the subnets and security groups inside that VPC. So in your new VPC, make sure you have the relevant security groups and subnets created - and then place those IDs into the above snippet.

Reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-vpcconfig