I've asked ChatGPT to give me an example on how to do this, it came up with the following:
public void publishMessage(String topicArn, String message) {
SnsClient snsClient = SnsClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();
PublishRequest publishRequest = PublishRequest.builder()
.topicArn(topicArn)
.message(message)
.build();
EventStreamAws4Signer signer = EventStreamAws4Signer.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();
SdkBytes payload = SdkBytes.fromByteArray(message.getBytes());
String signature = signer.sign(publishRequest, payload).get("signature");
snsClient.publish(builder -> builder
.message(message)
.topicArn(topicArn)
.signature(signature)
.build());
}
In reality EventStreamAws4Signer
doesn't have a builder() method, only a create() method.
But the latter method doesn't provide a way to configure the access keys or use the instance profile access keys for signing.
How do I use the EventStreamAws4Signer
to get a signature? I've looked at the code examples in the docs here: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/java_sns_code_examples.html and also in the code examples on github here: https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/sns/src/main/java/com/example/sns
But couldn't find what i was looking for. I need to know how I can both create a signature and how to validate a signature. Thank you
this is not helpful. I need to know how to create my own signature string and how to verify signature strings extracted from the headers of other SNS notifications