-
Notifications
You must be signed in to change notification settings - Fork 90
feat(sqs:large-message): Expose SDK v2 s3 client #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,4 +180,31 @@ processing. | |
return "ok"; | ||
} | ||
} | ||
``` | ||
|
||
## Passing custom S3Client | ||
|
||
If you need to pass custom S3Client such as region to the SDK, you can pass your own `S3Client` to be used by utility either for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wording change. "If you require customisations to the default S3Client, you can create your own S3Client and pass it to ......" |
||
**[SqsLargeMessage annotation](#lambda-handler)**, or **[SqsUtils Utility API](#utility)**. | ||
|
||
=== "App.java" | ||
|
||
```java hl_lines="4 5 11" | ||
import software.amazon.lambda.powertools.sqs.SqsLargeMessage; | ||
|
||
static { | ||
SqsUtils.overrideS3Client(S3Client.builder() | ||
.build()); | ||
} | ||
|
||
public class SqsMessageHandler implements RequestHandler<SQSEvent, String> { | ||
|
||
@Override | ||
@SqsLargeMessage | ||
public String handleRequest(SQSEvent sqsEvent, Context context) { | ||
// process messages | ||
|
||
return "ok"; | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
powertools-sqs/src/main/java/software/amazon/payloadoffloading/PayloadS3Pointer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package software.amazon.payloadoffloading; | ||
msailes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static java.util.Optional.empty; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class PayloadS3Pointer { | ||
private static final Logger LOG = LoggerFactory.getLogger(PayloadS3Pointer.class); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private String s3BucketName; | ||
private String s3Key; | ||
|
||
static { | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); | ||
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL); | ||
} | ||
|
||
private PayloadS3Pointer() { | ||
|
||
} | ||
|
||
public String getS3BucketName() { | ||
return this.s3BucketName; | ||
} | ||
|
||
public String getS3Key() { | ||
return this.s3Key; | ||
} | ||
|
||
public static Optional<PayloadS3Pointer> fromJson(String s3PointerJson) { | ||
try { | ||
return ofNullable(objectMapper.readValue(s3PointerJson, PayloadS3Pointer.class)); | ||
} catch (Exception e) { | ||
LOG.error("Failed to read the S3 object pointer from given string.", e); | ||
return empty(); | ||
} | ||
} | ||
|
||
public Optional<String> toJson() { | ||
try { | ||
ObjectWriter objectWriter = objectMapper.writer(); | ||
return ofNullable(objectWriter.writeValueAsString(this)); | ||
|
||
} catch (Exception e) { | ||
LOG.error("Failed to convert S3 object pointer to text.", e); | ||
return empty(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a change to
Overriding the default S3Client
to match the method name.