无需公网IP AWS上运行的Java SDK code公网、IP、AWS、code

2023-09-11 09:27:27 作者:丧尽良心

我们需要互联网连接在AWS实例中使用AWS的Java SDK的?

Do we need internet connectivity to use AWS Java SDK from within an instance in AWS ?

我有内部的VPC实例上运行,而我还没有分配任何公共IP地址。

I have an instance running inside a VPC to which I haven't assigned any public IP address.

这就是我最初的调查发现,我看到从这个例子亚马逊AWS运行Java SDK的基于Java程序,实例需要有互联网连接。

From what my initial investigation found out, I see that to run AWS Java SDK based Java programs from this instance in Amazon, the instance needs to have internet connectivity.

运行示例程序AwsConsoleApp随AWS Java SDK的,我看到了以下错误:

Running the sample program AwsConsoleApp that comes with AWS Java SDK, I saw following error:

[javac的] /home/ubuntu/aws-java-sdk-1.8.9.1/samples/AwsConsoleApp/build.xml:12:警告:includeantruntime'没有设置,默认为build.sysclasspath =最后;设置为false可重复的构建      【JAVA] ===========================================      【JAVA]欢迎AWS Java SDK的!      【JAVA] ===========================================

[javac] /home/ubuntu/aws-java-sdk-1.8.9.1/samples/AwsConsoleApp/build.xml:12: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [java] =========================================== [java] Welcome to the AWS Java SDK! [java] ===========================================

 [java] Sep 09, 2014 9:26:49 PM com.amazonaws.http.AmazonHttpClient executeHelper
 [java] INFO: Unable to execute HTTP request: Connect to ec2.us-east-1.amazonaws.com:443 timed out
 [java] org.apache.http.conn.ConnectTimeoutException: Connect to ec2.us-east-1.amazonaws.com:443 timed out
 [java]     at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:551)
 [java]     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
 [java]     at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
 [java]     at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:645)
 [java]     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:480)
 [java]     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
 [java]     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
 [java]     at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:464)
 [java]     at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:273)
 [java]     at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:9320)
 [java]     at com.amazonaws.services.ec2.AmazonEC2Client.describeAvailabilityZones(AmazonEC2Client.java:359)
 [java]     at com.amazonaws.services.ec2.AmazonEC2Client.describeAvailabilityZones(AmazonEC2Client.java:8045)
 [java]     at AwsConsoleApp.main(Unknown Source)
 [java] 

我发现这违背了如何Amazon提供访问其EC2Metadata服务。

I found this contrary to how Amazon provides Access to their EC2Metadata Service.

有什么办法,我没有提供AWS实例的公网IP​​可以运行这些Java程序?

Is there any way I can run these Java programs without providing the AWS instance public IP ?

推荐答案

您需要互联网连接,但它并不需要通过分配到你的code运行实例的公网IP​​。

You need Internet connectivity, but it doesn't need to be via a public IP assigned to the instance where your code is running.

的公网IP​​可以在一个NAT的情况下,它允许其他机器在您的VPC访问Internet,但不允许在互联网上的系统访问您的私人情况。

The public IP can be on a NAT instance, which allows other machines in your VPC to access the Internet, but doesn't allow systems on the Internet to access your private instances.

您开设一个专用子网中的虚拟私有云(VPC)的实例不能与Internet进行通信。您可以选择使用网络地址转换(NAT),例如在公共子网的VPC,使私人子网实例启动出站通信到互联网,但prevent自收到发起人的入站流量的情况下,互联网。

Instances that you launch into a private subnet in a virtual private cloud (VPC) can't communicate with the Internet. You can optionally use a network address translation (NAT) instance in a public subnet in your VPC to enable instances in the private subnet to initiate outbound traffic to the Internet, but prevent the instances from receiving inbound traffic initiated by someone on the Internet.

http://docs.aws.amazon.com/AmazonVPC/最新/ UserGuide / VPC_NAT_Instance.html

参见 http://stackoverflow.com/a/22212017/1695906 关于进一步讨论私与公共的子网,NAT实例和路由。

See also http://stackoverflow.com/a/22212017/1695906 for additional discussion about "private" vs "public" subnets, NAT instances, and routing.