AWS code-library medium security documentation change
Summary
Updated AWS SDK client initializations to use 'fromEnvironment' method instead of direct constructors, and reformatted SNS topic policy JSON for readability
Security assessment
The change to 'fromEnvironment()' method improves credential handling by leveraging environment variables/configuration rather than potential hard-coded credentials. This aligns with security best practices for credential management. The SNS policy reformatting doesn't introduce security fixes but ensures policy clarity. While not addressing an active exploit, the client initialization change promotes secure coding practices.
Diff
diff --git a/code-library/latest/ug/kotlin_1_eventbridge_code_examples.md b/code-library/latest/ug/kotlin_1_eventbridge_code_examples.md index b665e4f80..59a9f693d 100644 --- a//code-library/latest/ug/kotlin_1_eventbridge_code_examples.md +++ b//code-library/latest/ug/kotlin_1_eventbridge_code_examples.md @@ -45 +45 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-west-2" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-west-2" }.use { eventBrClient -> @@ -304 +304 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "us-east-1" }.use { iam -> + IamClient.fromEnvironment { region = "us-east-1" }.use { iam -> @@ -325 +325 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - S3Client { region = "us-east-1" }.use { s3Client -> + S3Client.fromEnvironment { region = "us-east-1" }.use { s3Client -> @@ -369 +369 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - SnsClient { region = "us-east-1" }.use { snsClient -> + SnsClient.fromEnvironment { region = "us-east-1" }.use { snsClient -> @@ -380 +380 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -393 +393 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -432 +432 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -462 +462 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -480 +480 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -514 +514 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -525 +525 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -550 +550 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -574 +574 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - S3Client { region = "us-east-1" }.use { s3Client -> + S3Client.fromEnvironment { region = "us-east-1" }.use { s3Client -> @@ -585 +585 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -599 +599 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -632 +632 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -650 +650 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - SnsClient { region = "us-east-1" }.use { snsClient -> + SnsClient.fromEnvironment { region = "us-east-1" }.use { snsClient -> @@ -657,13 +657,16 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - val topicPolicy = - "{" + - "\"Version\": \"2012-10-17\"," + - "\"Statement\": [{" + - "\"Sid\": \"EventBridgePublishTopic\"," + - "\"Effect\": \"Allow\"," + - "\"Principal\": {" + - "\"Service\": \"events.amazonaws.com\"" + - "}," + - "\"Resource\": \"*\"," + - "\"Action\": \"sns:Publish\"" + - "}]" + - "}" + val topicPolicy = """ + { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "EventBridgePublishTopic", + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Resource": "*", + "Action": "sns:Publish" + } + ] + } + """.trimIndent() @@ -680 +683 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - SnsClient { region = "us-east-1" }.use { snsClient -> + SnsClient.fromEnvironment { region = "us-east-1" }.use { snsClient -> @@ -694 +697 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -709 +712,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - val pattern = """{ + val pattern = """ + { @@ -717 +721,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - }""" + } + """.trimIndent() @@ -727 +732 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -751 +756 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - S3Client { region = "us-east-1" }.use { s3Client -> + S3Client.fromEnvironment { region = "us-east-1" }.use { s3Client -> @@ -764 +769 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - S3Client { region = "us-east-1" }.use { s3 -> + S3Client.fromEnvironment { region = "us-east-1" }.use { s3 -> @@ -781 +786 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - S3Client { region = "us-east-1" }.use { s3Client -> + S3Client.fromEnvironment { region = "us-east-1" }.use { s3Client -> @@ -808 +813 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - IamClient { region = "us-east-1" }.use { iam -> + IamClient.fromEnvironment { region = "us-east-1" }.use { iam -> @@ -859 +864 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -888 +893 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -930 +935 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -972 +977 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1001 +1006 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1033 +1038 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1065 +1070 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1110 +1115 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1147 +1152 @@ Create a scheduled rule. - EventBridgeClient { region = "us-west-2" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-west-2" }.use { eventBrClient -> @@ -1164 +1169,2 @@ Create a rule that triggers when an object is added to an Amazon Simple Storage - val pattern = """{ + val pattern = """ + { @@ -1172 +1178,2 @@ Create a rule that triggers when an object is added to an Amazon Simple Storage - }""" + } + """.trimIndent() @@ -1182 +1189 @@ Create a rule that triggers when an object is added to an Amazon Simple Storage - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1230 +1237 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1266 +1273 @@ Add an input transformer to a target for a rule. - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient -> @@ -1295 +1302 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> + EventBridgeClient.fromEnvironment { region = "us-east-1" }.use { eventBrClient ->