1
- # go-aws-news
1
+ # go-aws-news <!-- omit in toc -->
2
2
3
3
Fetch what's new from AWS and send out notifications on social sites.
4
4
@@ -11,28 +11,28 @@ Fetch what's new from AWS and send out notifications on social sites.
11
11
![ sourcegraph] ( https://sourcegraph.com/github.com/circa10a/go-aws-news/-/badge.svg )
12
12
[ ![ codecov] ( https://codecov.io/gh/circa10a/go-aws-news/branch/master/graph/badge.svg?token=1OLAEVOAIO )] ( https://codecov.io/gh/circa10a/go-aws-news )
13
13
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 )
36
36
37
37
## App Install
38
38
@@ -115,6 +115,52 @@ To apply the `cronjob.yaml` example above:
115
115
kubectl apply -f cronjob.yaml
116
116
```
117
117
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
+
118
164
# # Module Install
119
165
120
166
` 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"
127
173
128
174
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.
129
175
130
- #### Get Today's news
176
+ # ## Get Today's news
131
177
132
178
` ` ` go
133
179
package main
@@ -145,33 +191,33 @@ func main() {
145
191
}
146
192
` ` `
147
193
148
- #### Get Yesterday's news
194
+ # ## Get Yesterday's news
149
195
150
196
` ` ` go
151
197
news, _ := awsnews.Yesterday ()
152
198
` ` `
153
199
154
- #### Get all news for the month
200
+ # ## Get all news for the month
155
201
156
202
` ` ` go
157
203
news, _ := awsnews.ThisMonth ()
158
204
` ` `
159
205
160
- #### Get from a previous month
206
+ # ## Get from a previous month
161
207
162
208
` ` ` go
163
209
// Custom timeframe(June 2019)
164
210
news, err := awsnews.Fetch(2019, 06)
165
211
` ` `
166
212
167
- #### Get from a previous year
213
+ # ## Get from a previous year
168
214
169
215
` ` ` go
170
216
// Custom timeframe(2017)
171
217
news, err := awsnews.FetchYear(2017)
172
218
` ` `
173
219
174
- #### Print out announcements
220
+ # ## Print out announcements
175
221
176
222
` ` ` go
177
223
news, _ := awsnews.ThisMonth ()
@@ -189,7 +235,7 @@ news.Print()
189
235
//
190
236
` ` `
191
237
192
- #### Loop over news data
238
+ # ## Loop over news data
193
239
194
240
` ` ` go
195
241
// Loop slice of stucts of announcements
@@ -202,15 +248,15 @@ for _, v := range news {
202
248
}
203
249
` ` `
204
250
205
- #### Limit news results count
251
+ # ## Limit news results count
206
252
207
253
` ` ` go
208
254
news, _ := awsnews.ThisMonth ()
209
255
// Last 10 news items of the month
210
256
news.Last(10).Print ()
211
257
` ` `
212
258
213
- #### Get news as JSON
259
+ # ## Get news as JSON
214
260
215
261
` ` ` go
216
262
news, _ := awsnews.ThisMonth ()
@@ -221,15 +267,15 @@ if jsonErr != nil {
221
267
fmt.Println(string(json))
222
268
` ` `
223
269
224
- #### Get news as HTML
270
+ # ## Get news as HTML
225
271
226
272
` ` ` go
227
273
news, _ := awsnews.ThisMonth ()
228
274
html := news.HTML ()
229
275
fmt.Println(html)
230
276
` ` `
231
277
232
- #### Get news about a specific product
278
+ # ## Get news about a specific product
233
279
234
280
` ` ` go
235
281
news, err := awsnews.Fetch(2019, 12)
0 commit comments