-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (46 loc) · 1.35 KB
/
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
package main
import (
"github.com/aws/aws-lambda-go/lambda"
"net/http"
"io/ioutil"
"log"
"context"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/aws/aws-sdk-go/aws"
"bytes"
"os"
)
//noinspection GoUnusedFunction
func main() {
lambda.Start(lichterfestNotify)
}
func lichterfestUnchanged() (bool) {
resp, err := http.Get(os.Getenv("Url"))
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
return bytes.Contains(body, []byte(os.Getenv("UrlContains")))
}
//noinspection GoUnusedParameter
func lichterfestNotify(ctx context.Context, name string) (message string, err error) {
if lichterfestUnchanged() {
return "not_changed", nil
}
svc := sns.New(session.New())
params := &sns.PublishInput{
Message: aws.String(os.Getenv("NotificationMessage")), // This is the message itself (can be XML / JSON / Text - anything you want)
TopicArn: aws.String(os.Getenv("AwsSnsApplicationArn")), //Get this from the Topic in the AWS console.
}
_, err = svc.Publish(params)
if err != nil { //Check for errors
return "", err
}
// Pretty-print the response data.
return "changed", nil
}