awslabs / amazon-dynamodb-local-samples

This is a sample Java project that demonstrates how to use DynamoDB Local for local development and testing
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
MIT No Attribution
14 stars 8 forks source link

DynamoDBLocal embedded version of a mock throws an exception from setRegion method which is inconsistent with clients using HTTP connections #13

Closed klach-ocado closed 6 months ago

klach-ocado commented 7 months ago

Minimal example reproducing the problem: https://github.com/klach-ocado/dynamodblocal-setregion-issue


There is an exception in DynamoDBLocal when embedded version is used:

com.amazonaws.AmazonServiceException: Regions are not supported in LocalDynamoDB (Service: null; Status Code: 400; Error Code: InvalidAction; Request ID: null; Proxy: null)

    at com.amazonaws.services.dynamodbv2.local.embedded.DDBExceptionMappingInvocationHandler.handleDynamoDBLocalServiceException(DDBExceptionMappingInvocationHandler.java:50)
    at com.amazonaws.services.dynamodbv2.local.embedded.DDBExceptionMappingInvocationHandler.invoke(DDBExceptionMappingInvocationHandler.java:126)
    at jdk.proxy2/jdk.proxy2.$Proxy76.setRegion(Unknown Source)
    at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.setField(Worker.java:1262)
    at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.access$500(Worker.java:92)
    at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker$Builder.build(Worker.java:1477)
    at com.amazonaws.services.dynamodbv2.streamsadapter.StreamsWorkerFactory.createDynamoDbStreamsWorker(StreamsWorkerFactory.java:165)

For comparison, when Jetty version (or a client configured for production use) is used, the following code:

// com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.setField
    private static <S, T> void setField(final S source, final String field, final Consumer<T> t, T value) {
        try {
            t.accept(value);
        } catch (UnsupportedOperationException e) {
            LOG.debug("Exception thrown while trying to set " + field + ", indicating that "
                    + source.getClass().getSimpleName() + "is immutable.", e);
        }
    }

catches an exception thrown here:

// com.amazonaws.AmazonWebServiceClient.setRegion
    public void setRegion(Region region) throws IllegalArgumentException {
        checkMutability();
        // ...
    }

// com.amazonaws.AmazonWebServiceClient.checkMutability
    protected final void checkMutability() {
        if (isImmutable) {
            throw new UnsupportedOperationException(
                    "Client is immutable when created with the builder.");
        }
    }

... and no hacks have to be done in tests.

Since Spring Boot 3.2 requires Jetty 12 while DynamoDBLocal still uses Jetty 11, we need to use embedded version of the mock, or prepare even bigger hacks for DynamoDBLocal to work with Spring Boot 3.2.


What is expected as a fix?

Probably throwing UnsupportedOperationException in com.amazonaws.services.dynamodbv2.local.shared.access.awssdkv1.client.LocalAmazonDynamoDB#setRegion, or maybe simply removing that method, as the method in parent class (com.amazonaws.services.dynamodbv2.AbstractAmazonDynamoDB#setRegion) already throws UnsupportedOperationException.

I guess that potential changes in other AWS libraries designed for production use are more risky than changes in DynamoDBLocal.

shetsa-amzn commented 6 months ago

We appreciate your feedback and we are currently reviewing this. We will update as soon as we have more information about next steps.

shetsa-amzn commented 6 months ago

Hello @klach-ocado ,

The DynamoDB DevEx team is continuously making improvements to DynamoDB local. As we have received feedback from you as a user of DynamoDB local as a Maven dependency. Our latest improvement to DynamoDB local is an upgrade to Jetty 12 to be compatible with Spring Boot 3.2.0. We are reaching out to you to see if you would like to participate in the early testing of our DynamoDB local beta version, which includes this upgrade. We would really appreciate your support as your participation will help us ensure high quality user experience with this upgrade before we launch to the general public.

If you would like to participate in early testing of our DynamoDB local beta release, please send us an email at: aws-ddblocal-feedback@amazon.com.

Regards, The DynamoDB DevEx Team

shetsa-amzn commented 6 months ago

Today, we are excited to announce that DynamoDB local for Amazon DynamoDB upgrades to Jetty 12 and JDK 17. We recommend that you run the latest version (2.3.0) of DynamoDB local to utilize the most recent updates and features of DynamoDB local for your development and testing use cases.

https://aws.amazon.com/about-aws/whats-new/2024/03/amazon-dynamodb-local-upgrades-jetty-12-jdk-17/

klach-ocado commented 6 months ago

Hi, I'm not sure why this issue was closed. I still reproduce the problem using official 2.3.0 version of DynamoDBLocal. If it was closed by mistake, please reopen. If you do not plan to change the behaviour in the library, please state that explicitly. Thank you.