【发布时间】:2019-02-10 06:44:53
【问题描述】:
我用下面的CloudFormation 创建了VPC 和RDS。
Resources:
TestVpc:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsSupport: true
EnableDnsHostnames: true
TestSubnetA:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: "ap-northeast-1a"
CidrBlock: "10.0.0.0/20"
VpcId: !Ref TestVpc
TestSubnetB:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: "ap-northeast-1d"
CidrBlock: "10.0.16.0/20"
VpcId: !Ref TestVpc
TestSubnetC:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: "ap-northeast-1c"
CidrBlock: "10.0.32.0/20"
VpcId: !Ref TestVpc
TestSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Test security group with cloduformation"
SecurityGroupIngress:
- CidrIp: "10.0.0.0/16"
IpProtocol: "tcp"
FromPort: 0
ToPort: 65535
SecurityGroupEgress:
- CidrIp: "0.0.0.0/0"
FromPort: 0
ToPort: 65535
IpProtocol: "tcp"
VpcId: !Ref TestVpc
TestSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: "TestSubnetGroupDesc"
SubnetIds:
- !Ref TestSubnetA
- !Ref TestSubnetB
- !Ref TestSubnetC
TestRDS:
Type: "AWS::RDS::DBInstance"
Properties:
DBInstanceClass: "db.t2.micro"
DBInstanceIdentifier: "rekog-moderation"
DBName: "rekog"
Engine: "postgres"
EngineVersion: "10.4"
MasterUsername: "rekog"
MasterUserPassword: "passwd"
AllocatedStorage: "20"
DBSubnetGroupName: !Ref TestSubnetGroup
VPCSecurityGroups:
- !Ref TestSecurityGroup
RDS 的结果
Lambda 设置
Lambda 尝试使用域名rekog-moderation.cokqwd6ixsnc.ap-northeast-1.rds.amazonaws.com 访问时,在与RDS 建立连接时返回超时错误。
我错过了什么?
【问题讨论】:
-
在您的 Lambda 代码中添加调试语句到 resolve the DNS name of the Amazon RDS instance to an IP address。目的是属于
10.x.x.xIP 范围,这意味着它将纯粹在 VPC 内进行通信。另外,您能否将相关的 Lambda 代码添加到您的问题中? -
@John Rotenstein,非常感谢您再次发表评论,当我调试 lambda 代码时,这是因为在
VPC中访问了Rekognition。我应该为 lambda 设置NAT gateway以访问VPC之外的资源。
标签: amazon-web-services aws-lambda amazon-cloudformation amazon-rds