java - 如何跨区域解析CopySnapshotRequest 'protocol must not be null'

标签 java amazon-web-services amazon-ec2 aws-java-sdk aws-java-sdk-2.x

我正在尝试将 EC2 快照从一个区域移动到另一个区域。

创建基本 Ec2 快照副本并将其复制到第二个区域时,我收到错误协议(protocol)不能为空。当您到达代码中需要主机的位置时,主机似乎也为空。据我了解,在复制未加密的快照时,我不需要提供协议(protocol)(http/https)或主机详细信息。看来 AWS 代码应该在幕后执行此操作。

我突然觉得这似乎是一个 aws 问题,但目前关于 AWS SDK for Java V2 的反馈并不多,因为我已经在此处和 github 上进行了检查。

程序异常: java.lang.NullPointerException:协议(protocol)不能为空

我尝试将目标区域添加到构建器,但这也会导致相同的错误。

执行环境为Amazon Java 11.0.3 我已尝试使用 software.amazon.awssdk 版本 2.7.11 一直到 2.7.29

基本代码片段

    String amazonAccessKeyId = "amazonAccessKeyId";
    String amazonSecretKeyId = "amazonSecretKeyId";
    String baseRegionName = "baseRegionName"; // Region.AP_NORTHEAST_1.id(); or where ever your snapshot is located
    String remoteRegionName = "remoteRegionName "; // Region.AP_NORTHEAST_1.id(); or where ever your snapshot is located
    String snapshotId = "snapshotId"; // You will need a snapshot to work with this code

    // Setup AWS remote client with credentials
    AwsCredentials credentials = AwsBasicCredentials.create(amazonAccessKeyId, amazonSecretKeyId);

    Ec2Client amazonEc2RemoteRegionClient = Ec2Client.builder()
                    .region(Region.of(remoteRegionName))
                    .credentialsProvider(StaticCredentialsProvider.create(credentials))
                    .build();

    // Setup request
    CopySnapshotRequest request = CopySnapshotRequest.builder()
                    .sourceRegion(Region.of(baseRegionName).id())
                    .sourceSnapshotId(snapshotId)
                    .description("Foo Bar Testing...")
                    .build();

    // Invoke copy from remote region to pull in snapshot from source/default region
    // This is the line in question
    CopySnapshotResponse result = amazonEc2RemoteRegionClient.copySnapshot(request);

堆栈跟踪如下

java.lang.NullPointerException: protocol must not be null.
        at software.amazon.awssdk.utils.Validate.paramNotNull(Validate.java:117)
        at software.amazon.awssdk.http.DefaultSdkHttpFullRequest.standardizeProtocol(DefaultSdkHttpFullRequest.java:63)
        at software.amazon.awssdk.http.DefaultSdkHttpFullRequest.<init>(DefaultSdkHttpFullRequest.java:52)
        at software.amazon.awssdk.http.DefaultSdkHttpFullRequest.<init>(DefaultSdkHttpFullRequest.java:41)
        at software.amazon.awssdk.http.DefaultSdkHttpFullRequest$Builder.build(DefaultSdkHttpFullRequest.java:331)
        at software.amazon.awssdk.http.DefaultSdkHttpFullRequest$Builder.build(DefaultSdkHttpFullRequest.java:170)
        at software.amazon.awssdk.services.ec2.transform.internal.GeneratePreSignUrlInterceptor.modifyHttpRequest(GeneratePreSignUrlInterceptor.java:102)
        at software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain.modifyHttpRequestAndHttpContent(ExecutionInterceptorChain.java:99)
        at software.amazon.awssdk.core.client.handler.BaseClientHandler.runModifyHttpRequestAndHttpContentInterceptors(BaseClientHandler.java:123)
        at software.amazon.awssdk.core.client.handler.BaseClientHandler.finalizeSdkHttpFullRequest(BaseClientHandler.java:68)
        at software.amazon.awssdk.core.client.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:106)
        at software.amazon.awssdk.core.client.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:73)
        at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:44)
        at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:55)
        at software.amazon.awssdk.services.ec2.DefaultEc2Client.copySnapshot(DefaultEc2Client.java:2808)

我希望将快照复制到指定的新区域,没有错误,并且不加密。

作为旁注,我已通过我的支持系统将此信息提交给亚马逊,我正在等待他们的回复。一旦他们回复我的请求,我就会更新这篇文章。

最佳答案

复制快照 sdk错误,带有presignedUrl的builder可以跳过

关于java - 如何跨区域解析CopySnapshotRequest 'protocol must not be null',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57615776/

相关文章:

java - 关闭 AutoCompleteTextView 下拉列表

java - 如何将\n 与打印的字符串文字结合使用?

amazon-ec2 - Elasticsearch部署环境设置

xml - 上传 4GB 文件到 Amazon-S3

linux - rundeck - 在作业脚本中切换到 root 用户

java - 使用 Mockito 和 PowerMock 模拟私有(private)方法

java - 字符串的垃圾收集

python - 使用 Amazon Linux 的 Python 2.6.9 上的 mysql.connector 错误

amazon-web-services - 尝试通过 AWS : ssh 实例时出现问题

amazon-web-services - AWS Cognito不发送验证短信