Skip to content

Commit 8796767

Browse files
committed
Updated changes
1 parent 15bf028 commit 8796767

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/aws/aws-sdk-go/aws/session"
9+
"github.com/aws/aws-sdk-go/service/sns"
10+
)
11+
12+
func main() {
13+
err := SendSMS("Phone Number", "Hi, I am from AWS SNS")
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
18+
}
19+
20+
/*
21+
const (
22+
// Replace AccessKeyID with your AccessKeyID key.
23+
AccessKeyID = "Access Key"
24+
25+
// Replace AccessKeyID with your AccessKeyID key.
26+
SecretAccessKey = "Access Secret"
27+
28+
// Replace us-west-2 with the AWS Region you're using for Amazon SNS.
29+
AwsRegion = "us-west-2"
30+
)
31+
*/
32+
33+
func SendSMS(phoneNumber string, message string) error {
34+
// Create Session and assign AccessKeyID and SecretAccessKey
35+
/*
36+
sess, err := session.NewSession(&aws.Config{
37+
Region: aws.String(AwsRegion),
38+
Credentials: credentials.NewStaticCredentials(AccessKeyID, SecretAccessKey, ""),
39+
},
40+
)
41+
*/
42+
43+
//
44+
sess := session.Must(session.NewSessionWithOptions(session.Options{
45+
SharedConfigState: session.SharedConfigEnable,
46+
}))
47+
48+
// Create SNS service
49+
svc := sns.New(sess)
50+
51+
// Pass the phone number and message.
52+
params := &sns.PublishInput{
53+
PhoneNumber: aws.String(phoneNumber),
54+
Message: aws.String(message),
55+
}
56+
57+
// sends a text message (SMS message) directly to a phone number.
58+
resp, err := svc.Publish(params)
59+
60+
if err != nil {
61+
log.Println(err.Error())
62+
}
63+
64+
fmt.Println(resp) // print the response data.
65+
66+
return nil
67+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##Steps
2+
1.cd to path
3+
2.init go mod
4+
--go mod init test
5+
3.get go modules
6+
--go get github.com/aws/aws-sdk-go
7+
4.set aws context
8+
--aws configure
9+
4.run go file
10+
--go run .\awsSNS.go
11+

0 commit comments

Comments
 (0)