I have this piece of code:
private String putS3Object(String objectKey, String mimeType, byte[] content) {
S3Client s3 = S3Client.builder()
.region(Region.EU_CENTRAL_1) // Set region to eu-central-1
.build();
log.info("adding {} - {} - to {} ", objectKey, mimeType, bucketName);
try {
PutObjectResponse response = s3.putObject(PutObjectRequest.builder()
.bucket(bucketName)
.contentType(mimeType)
.key(objectKey)
.acl(ObjectCannedACL.PUBLIC_READ)
.build(),
RequestBody.fromBytes(content));
return response.eTag();
} catch (S3Exception e) {
log.error(e.getMessage());
}
return "";
}
but I have this error:
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: S3, Status Code: 301, Request ID: L75KCJ8A7K7WGQNS, Extended Request ID: BsqLF6F+HWW1CoEtVgZxe455hjsacpWCmWIXxwVFn7EnZgYleNPM7N818XYT8KP+8IpkWUA+iMOCRdgUFsy24438Q==)
and trying this is fine:
aws s3 cp pullpointer.svg s3://myxwaveq/
on the logs:
2024-12-17 17:10:32.233 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@connectSocket(366) - Connecting socket to myxwaveq.s3.eu-west-1.amazonaws.com/3.5.72.145:443 with timeout 2000
2024-12-17 17:10:32.257 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@createLayeredSocket(430) - Enabled protocols: [TLSv1.3, TLSv1.2]
2024-12-17 17:10:32.258 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@createLayeredSocket(431) - Enabled cipher suites:[TLS_AES_256_GCM_SHA384, TLS_AES_128_GCM_SHA256, TLS_CHACHA20_POLY1305_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2024-12-17 17:10:32.259 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@debug(84) - socket.getSupportedProtocols(): [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1, SSLv3, SSLv2Hello], socket.getEnabledProtocols(): [TLSv1.3, TLSv1.2]
2024-12-17 17:10:32.259 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@debug(84) - TLS protocol enabled for SSL handshake: [TLSv1.2, TLSv1.1, TLSv1, TLSv1.3]
2024-12-17 17:10:32.259 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@createLayeredSocket(435) - Starting handshake
2024-12-17 17:10:32.303 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(465) - Secure session established
2024-12-17 17:10:32.304 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(466) - negotiated protocol: TLSv1.3
2024-12-17 17:10:32.309 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(467) - negotiated cipher suite: TLS_AES_128_GCM_SHA256
2024-12-17 17:10:32.310 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(475) - peer principal: CN=*.s3-eu-west-1.amazonaws.com
2024-12-17 17:10:32.310 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(484) - peer alternative names: [s3-eu-west-1.amazonaws.com, *.s3-eu-west-1.amazonaws.com, s3.eu-west-1.amazonaws.com, *.s3.eu-west-1.amazonaws.com, s3.dualstack.eu-west-1.amazonaws.com, *.s3.dualstack.eu-west-1.amazonaws.com, *.s3.amazonaws.com, *.s3-control.eu-west-1.amazonaws.com, s3-control.eu-west-1.amazonaws.com, *.s3-control.dualstack.eu-west-1.amazonaws.com, s3-control.dualstack.eu-west-1.amazonaws.com, *.s3-accesspoint.eu-west-1.amazonaws.com, *.s3-accesspoint.dualstack.eu-west-1.amazonaws.com, *.s3-deprecated.eu-west-1.amazonaws.com, s3-deprecated.eu-west-1.amazonaws.com, s3-external-3.amazonaws.com, *.s3-external-3.amazonaws.com]
2024-12-17 17:10:32.311 [scheduling-1] DEBUG [] s.a.a.h.a.i.conn.SdkTlsSocketFactory@verifyHostname(488) - issuer principal: CN=Amazon RSA 2048 M01, O=Amazon, C=US
2024-12-17 17:10:32.314 [scheduling-1] DEBUG [] s.a.a.h.a.internal.net.SdkSslSocket@debug(84) - created: myxwaveq.s3.eu-west-1.amazonaws.com/3.5.72.145:443
2024-12-17 17:10:32.340 [scheduling-1] DEBUG [] software.amazon.awssdk.request@debug(84) - Received error response: software.amazon.awssdk.services.s3.model.S3Exception: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: S3, Status Code: 301, Request ID: V7kAQWWBTQ99YJKM5M12, Extended Request ID: VvTW1PA9XItafKTy7qGq7t3+vc98jiu5643yjPjUHjiW3FbDff1UtALT/L7KNt2/OXexiS6eVS2YaKuKeL3M/PN2MeSUW9Vjrfuotzyu)
2024-12-17 17:10:32.341 [scheduling-1] DEBUG [] s.a.a.h.a.internal.net.SdkSslSocket@debug(84) - closing myxwaveq.s3.eu-west-1.amazonaws.com/3.5.72.145:443
2024-12-17 17:10:32.343 [scheduling-1] ERROR [] c.m.service.ObjectStorageService@putS3Object(189) - The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: S3, Status Code: 301, Request ID: V127WBTQ9KLYJKM5M12, Extended Request ID: VvTW1PA9XItafKTl9b7qGq7t3+vcOyjPjUHjiW3FbDff1UtALT/L7KNt2/OXexiS6eVS2YaKuKeL3M/PN2MeSUW9Vjrfuotzyu)
2
Answers
You don’t have define the correct endpoint in your bucket S3 in your code.
Please modify to this :
Try using
endpointOverride(URI)
method to see if that fixes.Format of a regional endpoint:
Modify to this:
In your case:
References:
S3 Client Developer Guide Example
AWS Regional Endpoints