Short version: S3 events can contain non-standard characters. These cannot be used to build URLs to those s3 objects. Can event transformers escape these characters to build valid URLs?
I have an event bridge rule set up that sends notifications to SNS topics when files are uploaded to S3, so related parties who do not have regular developer access to S3 can access files created by batch jobs.
The filenames are somewhat dynamic, and can contain characters that must be escaped in order to display as a valid URL.
Example (truncated) event:
{
"version": "0",
"detail-type": "Object Created",
"source": "aws.s3",
"time": "2021-11-12T00:00:00Z",
"region": "ap-northeast-1",
"resources": ["arn:aws:s3:::example-bucket"],
"detail": {
"version": "0",
"bucket": {
"name": "example-bucket"
},
"object": {
"key": "exampleテスト.zip",
"size": 5,
"etag": "b1946ac92492d2347c6235b4d2611184",
"version-id": "IYV3p45BT0ac8hjHg1houSdS1a.Mro8e",
"sequencer": "00617F08299329D189"
},
"request-id": "N4N7GDK58NMKJ12R",
"requester": "123456789012",
"source-ip-address": "1.2.3.4",
"reason": "PutObject"
}
}
And my event transformer looks like this:
{
"message": "Batch job report has finished",
"URL": "https://<bucket>.s3.ap-northeast-1.amazonaws.com/<objectKey>"
}
This will just send the raw json to an SNS topic, which will forward it as-is to subscribers. The problem is that the url will end up being:
https://example-bucket.s3.ap-northeast-1.amazonaws.com/exampleテスト.zip
While stack overflow displays this as a valid URL, email clients do not. The URL ends at example
, because the Japanese characters are not escaped. This is the case for all characters that need to be escaped, including spaces and other languages.
I need a way to escape these characters in eventbridge. Is there a away, given the event above, to make the following transformer output?
{
"message": "Batch job report has finished",
"URL": "https://example-bucket.s3.ap-northeast-1.amazonaws.com/example%E3%83%86%E3%82%B9%E3%83%88.zip"
}