node.js - Setting up a NAT gateway with VPC using Serverless framework -


i'm trying use serverless framework create lambda function can access elasticache cluster, call out internet.

i've got far configuring serverless.yml create lambda function, create elasticache cluster (memcached engine), , create vpc , place both lambda function , elasticache cluster within (otherwise, cannot communicate).

i understand things within vpc not have access internet, , researching around topic i've come conclusion best practice way of handling create nat gateway vpc allow external access.

i can see how within aws console, i'd stick defining within serverless.yml avoid manual infrastructure setup.

  • is possible create nat gateway within serverless.yml?
  • is creating nat gateway correct way of doing this? (are there better options?)

additional information

in getting point i'm at, heavily copied 1 of serverless examples (it's java based example, concept , service definition same). creates lambda function, elasticache cluster, , puts them in vpc can communicate. believe has same issue whereby lambda function cannot access internet. https://github.com/mugglmenzel/serverless-examples-cached-rds-ws/blob/master/serverless.yml

you have configure nat instance or managed nat gateway provide internet access lambdas inside vpc. may have use resource section of serverless.yml file create nat gateway / nat instance resource.

have @ resources section of serverless framework documentation. these resources added cloudformation stack upon serverless deploy

you can overwrite/attach kind of resource cloudformation stack. can add resources, outputs or overwrite description. can use serverless variables sensitive data or reusable configuration in resources templates.

so can add cloudformation template nat gateway inside resource section.

for example,

resources:   natgateway:   type: aws::ec2::natgateway   dependson: nateip   properties:     allocationid:       fn::getatt:       - nateip       - allocationid     subnetid:       ref: publicsubnet   nateip:     type: aws::ec2::eip     properties:       domain: vpc   natroute:     type: aws::ec2::route     dependson: natgateway     properties:       routetableid:         ref: privateroutetable       destinationcidrblock: 0.0.0.0/0       natgatewayid:         ref: natgateway 

here link complete cloudformation snippet of lambda inside vpc.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -