Skip to content

Commit 84f1f2a

Browse files
authored
Merge pull request #54 from nickshine/run-as-lambda
setup to allow running in a lambda
2 parents 9fdab4e + 50c6f43 commit 84f1f2a

File tree

7 files changed

+180
-53
lines changed

7 files changed

+180
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.dylib
77
bin/
88
go-aws-news
9+
awsnews
910

1011
# Test binary, built with `go test -c`
1112
*.test

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ GOCMD=go
22
BINARY=awsnews
33
BUILD_FLAGS=-ldflags="-s -w"
44
PROJECT=circa10a/go-aws-news
5-
VERSION=1.1.2
5+
VERSION=1.2.0
66

77
test:
88
$(GOCMD) test -v ./... -coverprofile=coverage.txt
@@ -49,3 +49,12 @@ docker-release:
4949
echo "${DOCKER_PASSWORD}" | docker login -u ${DOCKER_USERNAME} --password-stdin
5050
docker push $(PROJECT):$(VERSION)
5151

52+
lambda-build:
53+
GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o bin/linux/amd64/$(BINARY)
54+
55+
lambda-package: lambda-build
56+
zip -j bin/lambda.zip bin/linux/amd64/$(BINARY)
57+
58+
lambda-run: lambda-build
59+
docker run --rm -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_REGION=us-east-1 \
60+
-v ${PWD}/bin/linux/amd64:/var/task:ro,delegated lambci/lambda:go1.x $(BINARY)

README.md

Lines changed: 80 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# go-aws-news
1+
# go-aws-news <!-- omit in toc -->
22

33
Fetch what's new from AWS and send out notifications on social sites.
44

@@ -11,28 +11,28 @@ Fetch what's new from AWS and send out notifications on social sites.
1111
![sourcegraph](https://sourcegraph.com/github.com/circa10a/go-aws-news/-/badge.svg)
1212
[![codecov](https://codecov.io/gh/circa10a/go-aws-news/branch/master/graph/badge.svg?token=1OLAEVOAIO)](https://codecov.io/gh/circa10a/go-aws-news)
1313

14-
[go-aws-news](#go-aws-news)
15-
* [App Install](#app-install)
16-
- [Notification Providers](#notification-providers)
17-
- [Install Options](#install-options)
18-
* [Install With Crontab](#install-with-crontab)
19-
* [Install As Kubernetes CronJob](#install-as-kubernetes-cronjob)
20-
* [Module Install](#module-install)
21-
* [Module Usage](#module-usage)
22-
- [Get Today's news](#get-todays-news)
23-
- [Get Yesterday's news](#get-yesterdays-news)
24-
- [Get all news for the month](#get-all-news-for-the-month)
25-
- [Get from a previous month](#get-from-a-previous-month)
26-
- [Get from a previous year](#get-from-a-previous-year)
27-
- [Print out announcements](#print-out-announcements)
28-
- [Loop over news data](#loop-over-news-data)
29-
- [Limit news results count](#limit-news-results-count)
30-
- [Get news as JSON](#get-news-as-json)
31-
- [Get news as HTML](#get-news-as-html)
32-
- [Get news about a specific product](#get-news-about-a-specific-product)
33-
* [Google Assistant Integration](#google-assistant)
34-
* [Development](#development)
35-
+ [Test](#test)
14+
- [App Install](#app-install)
15+
- [Notification Providers](#notification-providers)
16+
- [Install Options](#install-options)
17+
- [Install With Crontab](#install-with-crontab)
18+
- [Install As Kubernetes CronJob](#install-as-kubernetes-cronjob)
19+
- [Install As AWS Lambda](#install-as-aws-lambda)
20+
- [Module Install](#module-install)
21+
- [Module Usage](#module-usage)
22+
- [Get Today's news](#get-todays-news)
23+
- [Get Yesterday's news](#get-yesterdays-news)
24+
- [Get all news for the month](#get-all-news-for-the-month)
25+
- [Get from a previous month](#get-from-a-previous-month)
26+
- [Get from a previous year](#get-from-a-previous-year)
27+
- [Print out announcements](#print-out-announcements)
28+
- [Loop over news data](#loop-over-news-data)
29+
- [Limit news results count](#limit-news-results-count)
30+
- [Get news as JSON](#get-news-as-json)
31+
- [Get news as HTML](#get-news-as-html)
32+
- [Get news about a specific product](#get-news-about-a-specific-product)
33+
- [Google Assistant](#google-assistant)
34+
- [Development](#development)
35+
- [Test](#test)
3636

3737
## App Install
3838

@@ -115,6 +115,52 @@ To apply the `cronjob.yaml` example above:
115115
kubectl apply -f cronjob.yaml
116116
```
117117

118+
#### Install As AWS Lambda
119+
120+
1. Setup provider config in AWS SSM Parameter Store:
121+
122+
```shell
123+
aws ssm put-parameter --type SecureString --name go-aws-news-config --value "$(cat config.yaml)"
124+
```
125+
126+
>**Note:** Overriding the name `go-aws-news-config` will require an environment variable on
127+
the lambda function: `GO_AWS_NEWS_CONFIG_NAME`.
128+
129+
1. Create the Lambda execution role and add permissions:
130+
131+
```shell
132+
aws iam create-role --role-name go-aws-news-lambda-ex --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'
133+
134+
aws iam attach-role-policy --role-name go-aws-news-lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
135+
aws iam attach-role-policy --role-name go-aws-news-lambda-ex --policy-arn arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess
136+
```
137+
138+
1. Create the lambda function:
139+
140+
```shell
141+
make lambda-package
142+
aws lambda create-function --function-name go-aws-news --zip-file fileb://bin/lambda.zip --runtime go1.x --handler awsnews \
143+
--role $(aws iam get-role --role-name go-aws-news-lambda-ex --query Role.Arn --output text)
144+
```
145+
146+
1. Create a schedule for the lambda:
147+
148+
```shell
149+
aws events put-rule --schedule-expression "cron(0 14 * * ? *)" --name go-aws-news-cron
150+
151+
LAMBDA_ARN=$(aws lambda get-function --function-name go-aws-news --query Configuration.FunctionArn)
152+
aws events put-targets --rule go-aws-news-cron --targets "Id"="1","Arn"=$LAMBDA_ARN
153+
```
154+
155+
1. Allow the lambda function to be invoked by the schedule rule:
156+
157+
```shell
158+
EVENT_ARN=$(aws events describe-rule --name go-aws-news-cron --query Arn --output text)
159+
160+
aws lambda add-permission --function-name go-aws-news --statement-id eventbridge-cron \
161+
--action 'lambda:InvokeFunction' --principal events.amazonaws.com --source-arn $EVENT_ARN
162+
```
163+
118164
## Module Install
119165

120166
`go-aws-news` can be installed as a module for use in other Go applications:
@@ -127,7 +173,7 @@ go get -u "github.com/circa10a/go-aws-news/news"
127173

128174
Methods return a slice of structs which include the announcement title, a link, and the date it was posted as well an error. This allows you to manipulate the data in whichever way you please, or simply use `Print()` to print a nice ASCII table to the console.
129175
130-
#### Get Today's news
176+
### Get Today's news
131177
132178
```go
133179
package main
@@ -145,33 +191,33 @@ func main() {
145191
}
146192
```
147193
148-
#### Get Yesterday's news
194+
### Get Yesterday's news
149195
150196
```go
151197
news, _ := awsnews.Yesterday()
152198
```
153199
154-
#### Get all news for the month
200+
### Get all news for the month
155201
156202
```go
157203
news, _ := awsnews.ThisMonth()
158204
```
159205
160-
#### Get from a previous month
206+
### Get from a previous month
161207
162208
```go
163209
// Custom timeframe(June 2019)
164210
news, err := awsnews.Fetch(2019, 06)
165211
```
166212
167-
#### Get from a previous year
213+
### Get from a previous year
168214
169215
```go
170216
// Custom timeframe(2017)
171217
news, err := awsnews.FetchYear(2017)
172218
```
173219
174-
#### Print out announcements
220+
### Print out announcements
175221
176222
```go
177223
news, _ := awsnews.ThisMonth()
@@ -189,7 +235,7 @@ news.Print()
189235
//
190236
```
191237
192-
#### Loop over news data
238+
### Loop over news data
193239
194240
```go
195241
// Loop slice of stucts of announcements
@@ -202,15 +248,15 @@ for _, v := range news {
202248
}
203249
```
204250
205-
#### Limit news results count
251+
### Limit news results count
206252
207253
```go
208254
news, _ := awsnews.ThisMonth()
209255
// Last 10 news items of the month
210256
news.Last(10).Print()
211257
```
212258
213-
#### Get news as JSON
259+
### Get news as JSON
214260
215261
```go
216262
news, _ := awsnews.ThisMonth()
@@ -221,15 +267,15 @@ if jsonErr != nil {
221267
fmt.Println(string(json))
222268
```
223269
224-
#### Get news as HTML
270+
### Get news as HTML
225271
226272
```go
227273
news, _ := awsnews.ThisMonth()
228274
html := news.HTML()
229275
fmt.Println(html)
230276
```
231277
232-
#### Get news about a specific product
278+
### Get news about a specific product
233279
234280
```go
235281
news, err := awsnews.Fetch(2019, 12)

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ go 1.13
55
require (
66
github.com/PuerkitoBio/goquery v1.6.0
77
github.com/andybalholm/cascadia v1.2.0 // indirect
8+
github.com/aws/aws-lambda-go v1.20.0
9+
github.com/aws/aws-sdk-go v1.36.2
810
github.com/kr/text v0.2.0 // indirect
911
github.com/mattn/go-runewidth v0.0.9 // indirect
1012
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1113
github.com/olekukonko/tablewriter v0.0.4
1214
github.com/sirupsen/logrus v1.7.0
1315
github.com/stretchr/testify v1.6.1
14-
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
15-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
16+
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect
17+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
1618
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1719
gopkg.in/yaml.v2 v2.4.0
1820
)

go.sum

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
12
github.com/PuerkitoBio/goquery v1.6.0 h1:j7taAbelrdcsOlGeMenZxc2AWXD5fieT1/znArdnx94=
23
github.com/PuerkitoBio/goquery v1.6.0/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
34
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
45
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
56
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
67
github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
8+
github.com/aws/aws-lambda-go v1.20.0 h1:ZSweJx/Hy9BoIDXKBEh16vbHH0t0dehnF8MKpMiOWc0=
9+
github.com/aws/aws-lambda-go v1.20.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
10+
github.com/aws/aws-sdk-go v1.36.2 h1:UAeFPct+jHqWM+tgiqDrC9/sfbWj6wkcvpsJ+zdcsvA=
11+
github.com/aws/aws-sdk-go v1.36.2/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
12+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
13+
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
714
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
815
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
916
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1017
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1118
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
19+
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
20+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
21+
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
22+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
1223
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1324
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1425
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -21,32 +32,35 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
2132
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
2233
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
2334
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
35+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2436
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2537
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
38+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
39+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
2640
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
2741
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
2842
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
2943
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3044
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
3145
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
3246
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
47+
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
3348
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3449
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
3550
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
3651
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3752
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
3853
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
39-
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
4054
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
55+
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
56+
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
4157
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4258
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4359
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
4460
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4561
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
46-
golang.org/x/sys v0.0.0-20201110211018-35f3e6cf4a65 h1:Qo9oJ566/Sq7N4hrGftVXs8GI2CXBCuOd4S2wHE/e0M=
47-
golang.org/x/sys v0.0.0-20201110211018-35f3e6cf4a65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
48-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
49-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
62+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso=
63+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5064
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5165
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
5266
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -55,8 +69,11 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
5569
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5670
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
5771
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
58-
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
59-
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
72+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
73+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
74+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
6075
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
6176
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
6277
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
78+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
79+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
6+
"os"
57

8+
"github.com/aws/aws-lambda-go/lambda"
69
"github.com/circa10a/go-aws-news/providers"
710
log "github.com/sirupsen/logrus"
811

912
"github.com/circa10a/go-aws-news/news"
1013
)
1114

1215
func main() {
13-
news, err := news.Yesterday()
16+
if os.Getenv("AWS_EXECUTION_ENV") == "AWS_Lambda_go1.x" {
17+
lambda.Start(mainExec)
18+
} else {
19+
err := mainExec()
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
}
24+
}
1425

26+
func mainExec() error {
27+
news, err := news.Yesterday()
1528
if err != nil {
16-
log.Fatal(err)
29+
return err
1730
}
1831
if len(news) == 0 {
1932
log.Info("No news fetched. Skipping notifications.")
20-
log.Exit(0)
33+
return nil
2134
}
2235

2336
providers := providers.GetProviders()
2437

2538
if len(providers) == 0 {
26-
log.Fatal("No providers enabled. See config.yaml.")
39+
return errors.New("No providers enabled. See configuration.")
2740
}
2841
for _, p := range providers {
2942
log.Info(fmt.Sprintf("[%v] Provider registered", p.GetName()))
3043
p.Notify(news)
3144
}
45+
46+
return nil
3247
}

0 commit comments

Comments
 (0)