Created
October 9, 2018 09:36
-
-
Save RohitRox/2ab0d4fd105deb8c0fb7a052f1e9519a to your computer and use it in GitHub Desktop.
AWS Lambda in VPC with NAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Description: Sample SAM Template for AWS lambda in vpc | |
Resources: | |
NatEIP: | |
Type: AWS::EC2::EIP | |
Properties: | |
Domain: vpc | |
NatGateway: | |
Type: AWS::EC2::NatGateway | |
Properties: | |
AllocationId: !GetAtt ["NatEIP", "AllocationId"] | |
SubnetId: !ImportValue SubnetAZ1Public | |
NatRoute: | |
Type: AWS::EC2::Route | |
Properties: | |
RouteTableId: rtb-0f3a3daf84eb81ff5 | |
DestinationCidrBlock: 0.0.0.0/0 | |
NatGatewayId: !Ref NatGateway | |
DynamoVpcEndpoint: | |
Type: AWS::EC2::VPCEndpoint | |
Properties: | |
VpcId: !ImportValue VPC | |
RouteTableIds: | |
- rtb-0f3a3daf84eb81ff5 | |
ServiceName: com.amazonaws.us-east-1.dynamodb | |
LambdaSecurityGroup: | |
Type: AWS::EC2::SecurityGroup | |
Properties: | |
GroupName: sam-web-security-group | |
GroupDescription: App Security Group | |
VpcId: !ImportValue VPC | |
SecurityGroupIngress: | |
- CidrIp: 0.0.0.0/0 | |
IpProtocol: tcp | |
ToPort: 80 | |
FromPort: 80 | |
ApplesApiGateway: | |
Type: AWS::Serverless::Api | |
Properties: | |
StageName: live | |
DefinitionUri: ./swagger.yaml | |
Variables: | |
ListApplesFunction: !Ref ListApples | |
ListApples: | |
Type: AWS::Serverless::Function | |
Properties: | |
Handler: src/list.handler | |
Runtime: nodejs8.10 | |
Policies: | |
- AWSLambdaVPCAccessExecutionRole | |
Timeout: 5 | |
VpcConfig: | |
SecurityGroupIds: | |
- !Ref LambdaSecurityGroup | |
SubnetIds: | |
- !ImportValue SubnetAZ1Private | |
Events: | |
ListApples: | |
Type: Api | |
Properties: | |
RestApiId: !Ref ApplesApiGateway | |
Path: /apples | |
Method: get | |
Outputs: | |
ListApplesApi: | |
Description: "API Gateway endpoint URL for live stage for ListApples function" | |
Value: !Join ['', ['https://', !Ref ApplesApiGateway, '.execute-api.', !Ref 'AWS::Region', '.amazonaws.com/live/apples' ] ] | |
ListApplesFunction: | |
Description: "ListApples Lambda Function ARN" | |
Value: !GetAtt ListApples.Arn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment