README ¶
AWS SDK for Go V2 code examples for Amazon SNS
Purpose
These examples demonstrates how to perform several Amazon Simple Notification Service (Amazon SNS) operations using version 2 of the AWS SDK for Go.
Prerequisites
You must have an AWS account, and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
Running the code
CreateTopic/CreateTopicv2.go
This example creates an Amazon SNS topic.
go run CreateTopicv2.go -t TOPIC
- TOPIC is the name of the topic to create.
The unit test accepts a similar value in config.json.
ListSubscriptions/ListSubscriptionsv2.go
This example lists the topic and subscription Amazon Resource Names (ARNs) for your Amazon SNS subscriptions.
go run ListSubscriptionsv2.go
ListTopics/ListTopicsv2.go
This example lists the ARNs for your Amazon SNS topics.
go run ListTopicsv2.go
Publish/Publishv2.go
This example publishes a message to an Amazon SNS topic.
go run Publishv2.go -m MESSAGE -t TOPIC-ARN
- MESSAGE is the message to publish.
- TOPIC-ARN is the ARN of the topic to which the message is published.
The unit test accepts similar values in config.json.
Subscribe/Subscribev2.go
This example subscribes a user, by email address, to an Amazon SNS topic.
go run Subscribev2.go -m EMAIL-ADDRESS -t TOPIC-ARN
- EMAIL-ADDRESS is the email address of the user subscribing to the topic.
- TOPIC-ARN is the ARN of the topic.
The unit test accepts a similar value in config.json.
Notes
- We recommend that you grant this code least privilege, or at most the minimum permissions required to perform the task. For more information, see Grant Least Privilege in the AWS Identity and Access Management User Guide.
- This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions.
- Running this code might result in charges to your AWS account.
Running the unit tests
Unit tests should delete any resources they create. However, they might result in charges to your AWS account.
To run a unit test, enter:
go test
You should see something like the following, where PATH is the path to the folder containing the Go files:
PASS
ok PATH 6.593s
If you want to see any log messages, enter:
go test -v
You should see some additional log messages. The last two lines should be similar to the previous output shown.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0