0

내 람다 함수가 내 RDS 서버와 통신 할 수있는 VPC 설정이 있습니다. 이것은 작동 중입니다. 또한 인터넷에 액세스하려면 람다 함수가 필요합니다. 이 목적을 위해 인터넷 게이트웨이와 라우트를 허용하도록 설정하려고합니다. 나는 실패하고있다.VPC에서 클라우드 정보를 통해 인터넷에 액세스하도록하려면 어떻게해야합니까?

상기 VPC 경로 및 게이트웨이 내가 서브넷을 만들고

"SubnetA": { 
    "Type": "AWS::EC2::Subnet", 
    "Properties": { 
    "VpcId": { "Ref": "VPC" }, 
    "CidrBlock": "10.0.0.0/24", 
    "AvailabilityZone": { "Fn::Select": [ "0", { "Fn::GetAZs": { "Ref": "AWS::Region" } }]}, 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"SubnetB": { 
    "Type": "AWS::EC2::Subnet", 
    "Properties": { 
    "VpcId": { "Ref": "VPC" }, 
    "CidrBlock": "10.0.1.0/24", 
    "AvailabilityZone": { "Fn::Select": [ "1", { "Fn::GetAZs": { "Ref": "AWS::Region" } }]}, 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"SubnetARouteTableAssociation" : { 
    "Type" : "AWS::EC2::SubnetRouteTableAssociation", 
    "Properties" : { 
     "SubnetId" : { "Ref" : "SubnetA" }, 
     "RouteTableId" : { "Ref" : "VPCRouteTable" } 
    } 
}, 

"SubnetBRouteTableAssociation" : { 
    "Type" : "AWS::EC2::SubnetRouteTableAssociation", 
    "Properties" : { 
     "SubnetId" : { "Ref" : "SubnetB" }, 
     "RouteTableId" : { "Ref" : "VPCRouteTable" } 
    } 
}, 

내가 데이터베이스 보안 그룹을이 경로 테이블과 연결 다음

"VPC": { 
    "Type": "AWS::EC2::VPC", 
    "Properties": { 
    "CidrBlock": "10.0.0.0/16", 
    "EnableDnsSupport": "true", 
    "EnableDnsHostnames": "true", 
    "InstanceTenancy": "default", 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"VPCRouteTable" : { 
    "Type" : "AWS::EC2::RouteTable", 
    "Properties" : { 
     "VpcId" : { "Ref" : "VPC" }, 
     "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"InternetGateway" : { 
    "Type" : "AWS::EC2::InternetGateway", 
    "Properties" : { 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"AttachGateway": { 
    "Type" : "AWS::EC2::VPCGatewayAttachment", 
    "Properties" : { 
     "VpcId" : { "Ref" : "VPC" }, 
     "InternetGatewayId" : { "Ref" : "InternetGateway" } 
    } 
}, 

"InternetRoute" : { 
    "Type" : "AWS::EC2::Route", 
    "DependsOn" : "InternetGateway", 
    "Properties" : { 
     "RouteTableId" : { "Ref" : "VPCRouteTable" }, 
     "DestinationCidrBlock" : "0.0.0.0/0", 
     "GatewayId" : { "Ref" : "InternetGateway" } 
    } 
}, 

로 만들어집니다

"DBSubnetGroup": { 
    "Type": "AWS::RDS::DBSubnetGroup", 
    "Properties": { 
    "DBSubnetGroupDescription": "Database Access", 
    "SubnetIds" : [{ "Ref": "SubnetA" }, { "Ref": "SubnetB" }], 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

"DBEC2SecurityGroup": { 
    "Type": "AWS::EC2::SecurityGroup", 
    "Properties": { 
    "GroupDescription": "Security group for RDS DB Instance", 
    "VpcId": {"Ref": "VPC"}, 
    "SecurityGroupIngress" : [{ 
     "IpProtocol": "tcp", 
     "FromPort": "3306", 
     "ToPort": "3306", 
     "CidrIp": "10.0.0.0/16" 
    }], 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

및 람다 보안 그룹

"LambdaSecurityGroup": { 
    "Type": "AWS::EC2::SecurityGroup", 
    "Properties": { 
    "GroupDescription": "Security group for Lambda", 
    "VpcId": {"Ref": "VPC"}, 
    "Tags" : [{ "Key": "Name", "Value": { "Ref": "DomainName" } }] 
    } 
}, 

그래서 지금 내 람다는 데이터베이스와 대화 할 수 있습니다. 하지만 그들은 인터넷에 연결할 수 없습니다. 내가 뭘 놓치고 있니?

답변

1

람다 함수가 VPC 리소스와 인터넷에 모두 액세스해야하는 경우 public 및 private 두 서브넷을 만듭니다. 개인 서브넷에 람다를 넣고 공용 서브넷에 NAT를 구성하십시오. 당신의 람다 기능은 인터넷 접속이 필요한 경우 따라서 http://docs.aws.amazon.com/lambda/latest/dg/vpc.html

에서

, 당신은 NAT 구성 할 수 있습니다 ( 예를 들면, 아마존 운동성 등 VPC 엔드 포인트가없는 AWS 서비스에 액세스하기 위해) VPC 또는 에있는 인스턴스를 사용하면 Amazon VPC NAT 게이트웨이를 사용할 수 있습니다. 자세한 내용은 Amazon VPC 사용 설명서의 NAT 게이트웨이를 참조하십시오.

+0

필자는 더 비싼 ec2가 더 이상 NAT를 실행하지 않아도된다는 것을 이해합니다. AWS는 이러한 이유로 인터넷 게이트웨이를 만들었습니다. 나는 ec2 인스턴스를 실행할 욕망이 없습니다. – Justin808

+0

@ Justin808 이해가 잘못되었습니다. 인터넷 게이트웨이는 공용 IP 주소가 연관된 공용 서브넷의 엔티티에서만 사용됩니다. 람다 컨테이너, NAT 게이트웨이 (EC2 인스턴스에서 실행되지 않음) 또는 NAT 인스턴스 (물론 EC2 인스턴스)를 포함하여 공용 IP 주소가없는 모든 엔티티에서 인터넷에 액세스하려면 ** 필수입니다 ** . t2.nano를 ~ $ 5/mo에 대해 완벽하게 훌륭한 NAT 인스턴스로 사용할 수 있습니다. –