question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The SDK v2 does not provide a Regions enum like v1 used to (was: Missing us-east-1 in BucketLocationConstraint)

See original GitHub issue

Describe the bug

We are using BucketLocationConstraint to bind application properties to a valid S3 Region.

Related : https://github.com/aws/aws-sdk-java-v2/issues/1324

Expected Behavior

The object s3Region is instantiated.

Current Behavior

java.lang.IllegalArgumentException: No enum constant software.amazon.awssdk.services.s3.model.BucketLocationConstraint.us-east-1

Reproduction Steps

demo.s3.region: "us-east-1"
@ConfigurationProperties("demo")
public class S3Properties {
    BucketLocationConstraint s3Region;
}

Possible Solution

Add the missing value(s) to service-2.json

Additional Information/Context

Note: this value is then passed to the S3Client builder like so :

S3Client.builder()
    .region(Region.of(s3Properties.getRegion().toString()))

We looked into using a Region enum directly, but we could not find an equivalent of the Regions enum from AWS SDK v1.

AWS Java SDK version used

2.17.246

JDK version used

17.0.4

Operating System and version

macOS Monterey 12.5

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pybeaudouincommented, Aug 6, 2022

@maciejwalkowiak Thank you for your help.

This is not a Spring Boot issue. In fact, it is able to bind Strings to Regions without a converter.

The issue is that Region allows building objects with invalid region identifiers, such as “first”.

Using the AWS SDK for Java v1, one can use the enum Regions and get type safety.

Using the AWS SDK for Java v2, I ended up building my own wrapper :

// Lombok imports
@Getter
@FieldDefaults(level = AccessLevel.PRIVATE)
public static class S3BucketRegion {
  String id;

  /** This constructor is used by Spring to bind properties. */
  public S3BucketRegion(String id) {
    if ("us-east-1".equals(id)) {
      this.id = id;
      return;
    }

    final var bucketLocation = BucketLocationConstraint.fromValue(id);
    if (bucketLocation != null && bucketLocation != UNKNOWN_TO_SDK_VERSION) {
      this.id = id;
      return;
    }

    throw new IllegalArgumentException("Unsupported AWS S3 region id : " + id);
  }
}
0reactions
github-actions[bot]commented, Aug 26, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regions (AWS SDK for Java - 1.12.363)
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate...
Read more >
types - Go Packages
In terms of implementation, a Bucket is a resource. An Amazon S3 bucket name is globally unique, and the namespace is shared by...
Read more >
aws "Cannot create enum from " + regionName + " value!"
The latest version of the Java SDK as of this answer (1.11.13) supports the following Regions: Enum Name Regions.GovCloud us-gov-west-1 Regions.
Read more >
BucketLocationConstraint (AWS SDK for Java - 2.18.17)
declaration: package: software.amazon.awssdk.services.s3.model, enum: BucketLocationConstraint.
Read more >
https://raw.githubusercontent.com/aws/aws-sdk-go/m...
Amazon S3 transfer acceleration does not support cross-Region copies. ... signature calculations // in Signature Version 4 must use us-east-1 as the Region, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found