-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (45 loc) · 1007 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"io/ioutil"
"log"
"strings"
"math/rand"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/sns"
)
func ReadShrekLine() string {
content, err := ioutil.ReadFile("include/shrek.txt")
if err != nil {
log.Fatal(err)
}
sentences := strings.Split(string(content), ".")
randomIndex := rand.Intn(len(sentences))
pick := sentences[randomIndex]
log.Println(pick)
return pick;
}
func Handler(ctx context.Context) error {
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
log.Fatalf("failed to load configuration, %v", err)
return err
}
client := sns.NewFromConfig(cfg)
message := ReadShrekLine()
phoneNumber := string("todo read from config")
output, err := client.Publish(ctx, &sns.PublishInput{
Message: &message,
PhoneNumber: &phoneNumber,
})
if err != nil {
log.Fatal(err)
return err
}
log.Print(output)
return nil
}
func main() {
lambda.Start(Handler)
}