# Lamda function on multi VPC with peering

**URL:** <https://forum.serverless.com/t/lamda-function-on-multi-vpc-with-peering/1431>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [March 4, 2017, 6:32pm UTC](https://forum.serverless.com/t/lamda-function-on-multi-vpc-with-peering/1431 "2017-03-04T18:32:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![khinester](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/khinester/32/315_2.png) [@khinester](https://forum.serverless.com/u/khinester)\
**Post date:** [March 4, 2017, 6:32pm UTC](https://forum.serverless.com/t/lamda-function-on-multi-vpc-with-peering/1431/1 "2017-03-04T18:32:36Z")

</div>

Hello, I have deployed my lambda function on a single VPC but would like to access a mongo cluster which is on another VPC.

I have configured the two VPC’s as detailed here [http://docs.aws.amazon.com/AmazonVPC/latest/PeeringGuide/peering-configurations-full-access.html#two-vpcs-full-access](http://docs.aws.amazon.com/AmazonVPC/latest/PeeringGuide/peering-configurations-full-access.html#two-vpcs-full-access).

But my lambda is still not able to access the mongo cluster?

This is the error I get

```
START RequestId: 99bafb83-006e-11e7-bbbe-53bef2a40123 Version: $LATEST
2017-03-04 00:07:48.376 (+00:00)	99bafb83-006e-11e7-bbbe-53bef2a40123	AUTH: { role: 'admin' }
2017-03-04 00:08:18.428 (+00:00)	99bafb83-006e-11e7-bbbe-53bef2a40123	MONGO: { [MongoError: no valid replicaset members found]
  name: 'MongoError',
  message: 'no valid replicaset members found' }
END RequestId: 99bafb83-006e-11e7-bbbe-53bef2a40123
REPORT RequestId: 99bafb83-006e-11e7-bbbe-53bef2a40123	Duration: 30055.73 ms	Billed Duration: 30100 ms Memory Size: 1024 MB	Max Memory Used: 68 MB	

```

I followed [https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7](https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7) to setup the Lambda VPC as it needed internet access and this works, but now, the question is how to access the mongodb VPC from within that VPC?

Here is the serverless.yml, I am using

```
service: serverless-functions

provider:
  name: aws
  runtime: nodejs4.3
  stage: ${opt:stage}
  region: us-east-1
  custom:
    envs:
      local:
        MONGO_URI: mongodb://localhost:27017/dev
      dev:
        MONGO_URI: mongodb://user:password@172.31.16.2:27017,172.31.63.14:27017,172.31.8.20:27017/dev?replicaSet=mongo

  iamRoleStatements:
    - Effect: Allow
      Action:
        - ec2:CreateNetworkInterface
        - ec2:DescribeNetworkInterfaces
        - ec2:DetachNetworkInterface
        - ec2:DeleteNetworkInterface
      Resource: "*"
    - Effect: "Allow"
      Action:
        - "s3:*"
      Resource: "*"
  environment:
    MONGO_URI: ${self:provider.custom.envs.${self:provider.stage}.MONGO_URI}

vpc:
  securityGroupIds:
    - sg-d4xxxxxx
  subnetIds:
    - subnet-adxxxxxx
    - subnet-d5xxxxxx
    - subnet-10xxxxxx
    - subnet-45xxxxxx
    - subnet-acxxxxxx
    - subnet-d6xxxxxx
    - subnet-11xxxxxx
    - subnet-40xxxxxx

functions:
  healthz:
    handler: build/main.healthz
    events:
      - http:
          path: healthz
          method: get
          cors: true

  graphql:
    handler: build/main.graphql
    timeout: 60
    memory: 1024
    events:
      - http:
          path: graphql
          method: post
          cors: true

plugins:
  - serverless-offline

```

I have configure the routing tables as detailed here: [http://docs.aws.amazon.com/AmazonVPC/latest/PeeringGuide/vpc-peering-routing.html](http://docs.aws.amazon.com/AmazonVPC/latest/PeeringGuide/vpc-peering-routing.html)

Any advice is much appreciated
