gpt4 book ai didi

java - 使用 java 从具有私有(private)子网的 ec2 实例访问 amazon Dynamodb

转载 作者:太空宇宙 更新时间:2023-11-04 12:09:22 26 4
gpt4 key购买 nike

我使用 spring 数据进行连接,如下所示:

@Bean
public AmazonDynamoDB amazonDynamoDB() {

BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY,

SECRET_KEY);

final AmazonDynamoDBClient client = new

AmazonDynamoDBClient(credentials);

client.withEndpoint(END_POINT);

//client.withRegion(Regions.AP_SOUTH_1);

client.withRegion(Regions.US_WEST_2);
return client;
}

但是我面临 Caused by: org.apache.http.conn.ConnectTimeoutException: Connect

至 dynamodb.us-west-2.amazonaws.com:443

在具有公有子网的 EC2 实例中,它工作正常。

请建议我如何从具有私有(private)子网的 ec2 实例访问 DynamoDB。

最佳答案

如果没有 NAT 网关或 NAT 实例,您无法从私有(private)子网上的实例连接到 DynamoDB 或许多其他 AWS 服务(例如 SQS 或 SNS)。

NAT

You can use a NAT device to enable instances in a private subnet to connect to the Internet (for example, for software updates) or other AWS services, but prevent the Internet from initiating connections with the instances. A NAT device forwards traffic from the instances in the private subnet to the Internet or other AWS services, and then sends the response back to the instances. When traffic goes to the Internet, the source IP address is replaced with the NAT device’s address and similarly, when the response traffic goes to those instances, the NAT device translates the address back to those instances’ private IP addresses.

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat.html

另请参阅Why do we need private subnets in VPC?

关于java - 使用 java 从具有私有(private)子网的 ec2 实例访问 amazon Dynamodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40013425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com