Documentation
¶
Overview ¶
Package sns provides a wrapper for publishing messages to AWS SNS. Implementations in this package also include distributed tracing capabilities by default.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶ added in v0.73.0
type API interface {
Publish(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error)
}
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher is an implementation of the Publisher interface with added distributed tracing capabilities.
Example ¶
// Create the SNS API with the required config, credentials, etc.
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
if service == sns.ServiceID && region == "eu-west-1" {
return aws.Endpoint{
URL: "http://localhost:4575",
SigningRegion: "eu-west-1",
}, nil
}
// returning EndpointNotFoundError will allow the service to fallback to it's default resolution
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("eu-west-1"),
config.WithEndpointResolverWithOptions(customResolver),
config.WithCredentialsProvider(aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider("aws-id", "aws-secret", "aws-token"))),
)
if err != nil {
log.Fatal(err)
}
api := sns.NewFromConfig(cfg)
// Create the publisher
pub, err := New(api)
if err != nil {
log.Fatal(err)
}
input := &sns.PublishInput{
Message: aws.String("my message"),
TargetArn: nil, TopicArn: aws.String("arn:aws:sns:eu-west-1:123456789012:MyTopic"),
}
// Publish it
msgID, err := pub.Publish(context.Background(), input)
if err != nil {
log.Fatal(err)
}
fmt.Println(msgID)
Click to show internal directories.
Click to hide internal directories.