aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.21k stars 854 forks source link

EC2 copy EBS snapshot missing protocol. #1564

Closed blakemorgan closed 4 years ago

blakemorgan commented 4 years ago

When I try to use the copySnapshot() method with the EC2 client, I get a null pointer exception with the message that the "protocol must not be null"

Expected Behavior

The EBS snapshot should be copied from one region to another.

Current Behavior

Currently, I get the following error:

Exception in thread "main" 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:104)
    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:3020)
    at software.amazon.awssdk.services.ec2.Ec2Client.copySnapshot(Ec2Client.java:3900)
    at edu.byu.artifactoryLambda.Handler.backupEbs(Handler.kt:101)
    at edu.byu.artifactoryLambda.Handler.handleRequest(Handler.kt:46)
    at edu.byu.artifactoryLambda.HandlerKt.main(Handler.kt:28)
    at edu.byu.artifactoryLambda.HandlerKt.main(Handler.kt)

Process finished with exit code 130 (interrupted by signal 2: SIGINT)

Possible Solution

Include the protocol when the URL is getting signed

Steps to Reproduce (for bugs)

        val latestSnapshot = ec2Client.describeSnapshots { request ->
            request.filters(Filter.builder().name("volume-id").values(currentVolumeId).build())
        }.snapshots()[0]

        ec2Client.copySnapshot { request ->
            request.description("Artifactory backup ${latestSnapshot.startTime()}")
                .sourceRegion("us-west-2")
                .sourceSnapshotId(latestSnapshot.snapshotId())
                .destinationRegion("us-east-1")
        }

Context

I need to make a backup of an EBS snapshot from one region to another so I can have data recovery if needed.

Your Environment

zoewangg commented 4 years ago

The error indicates that the endpoint passed to the client does not have a protocol, i.e, "https" or "http".

blakemorgan commented 4 years ago

Yes. I am not passing any endpoint to the client however, because I never needed to for any of my other calls using that client. That's why I suspect it's a bug in the SDK.

zoewangg commented 4 years ago

I see. I thought you were using a customized endpoint without a protocol and yes, it seems like a bug in the SDK.