• Stars
    star
    17
  • Rank 1,257,025 (Top 25 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go app + library to fetch what's new from AWS

go-aws-news

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

Build Status PkgGoDev Go Report Card GitHub release (latest by date) codecov

App Install

go-aws-news can be executed as an application that sends out notifications to social sites like Discord. To configure providers, modify the config.yaml file to enable a provider.

go-aws-news is designed to be run on a schedule, once a day (displaying the previous day's AWS News). See the install options for examples on how to install and run.

Notification Providers

Currently supported providers:

Install Options

Install With Crontab

The simplest way to run go-aws-news is via crontab.

Type crontab -e on Mac or Linux and add a line:

# Binary
0 2 * * * /path/to/go-aws-news-binary
# Docker
0 14 * * * docker run -d --rm --name aws-news \
  -v your_config.yaml:/config.yaml \
  circa10a/go-aws-news

The above example will execute go-aws-news at 2PM UTC (8AM CST) each day.

Install As Kubernetes CronJob

go-aws-news can be run as a CronJob in a Kubernetes cluster.

Example cronjob.yaml:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: go-aws-news
spec:
  schedule: "0 14 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: go-aws-news
            image: circa10a/go-aws-news
            volumeMounts:
            - name: config
              mountPath: /config.yaml
              subPath: config.yaml
          volumes:
          - name: config
            configMap:
              name: awsnews-config
          restartPolicy: OnFailure

The ConfigMap can be created from the config.yaml file itself:

kubectl create configmap awsnews-config --from-file=config.yaml

To apply the cronjob.yaml example above:

kubectl apply -f cronjob.yaml

Install As AWS Lambda

  1. Setup provider config in AWS SSM Parameter Store:

    aws ssm put-parameter --type SecureString --name go-aws-news-config --value "$(cat config.yaml)"

    Note: Overriding the name go-aws-news-config will require an environment variable on the lambda function: GO_AWS_NEWS_CONFIG_NAME.

  2. Create the Lambda execution role and add permissions:

    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"}]}'
    
    aws iam attach-role-policy --role-name go-aws-news-lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
    aws iam attach-role-policy --role-name go-aws-news-lambda-ex --policy-arn arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess
  3. Create the lambda function:

    make lambda-package
    aws lambda create-function --function-name go-aws-news --zip-file fileb://bin/lambda.zip --runtime go1.x --handler awsnews \
      --role $(aws iam get-role --role-name go-aws-news-lambda-ex --query Role.Arn --output text)
  4. Create a schedule for the lambda:

    aws events put-rule --schedule-expression "cron(0 14 * * ? *)" --name go-aws-news-cron
    
    LAMBDA_ARN=$(aws lambda get-function --function-name go-aws-news --query Configuration.FunctionArn)
    aws events put-targets --rule go-aws-news-cron --targets "Id"="1","Arn"=$LAMBDA_ARN
  5. Allow the lambda function to be invoked by the schedule rule:

    EVENT_ARN=$(aws events describe-rule --name go-aws-news-cron --query Arn --output text)
    
    aws lambda add-permission --function-name go-aws-news --statement-id eventbridge-cron \
      --action 'lambda:InvokeFunction' --principal events.amazonaws.com --source-arn $EVENT_ARN

Module Install

go-aws-news can be installed as a module for use in other Go applications:

go get -u "github.com/circa10a/go-aws-news/news"

Module Usage

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.

Get Today's news

package main

import (
  awsnews "github.com/circa10a/go-aws-news/news"
)

func main() {
    news, err := awsnews.Today()
    if err != nil {
      // Handle error
    }
    news.Print()
}

Get Yesterday's news

news, _ := awsnews.Yesterday()

Get all news for the month

news, _ := awsnews.ThisMonth()

Get from a previous month

// Custom timeframe(June 2019)
news, err := awsnews.Fetch(2019, 06)

Get from a previous year

// Custom timeframe(2017)
news, err := awsnews.FetchYear(2017)

Print out announcements

news, _ := awsnews.ThisMonth()
news.Print()
// Console output
// +--------------------------------+--------------+
// |          ANNOUNCEMENT          |     DATE     |
// +--------------------------------+--------------+
// | Amazon Cognito now supports    | Jan 10, 2020 |
// | CloudWatch Usage Metrics       |              |
// +--------------------------------+--------------+
// | Introducing Workload Shares in | Jan 10, 2020 |
// | AWS Well-Architected Tool      |              |
// +--------------------------------+--------------+
//

Loop over news data

// Loop slice of stucts of announcements
// For your own data manipulation
news, _ := awsnews.Fetch(time.Now().Year(), int(time.Now().Month()))
for _, v := range news {
    fmt.Printf("Title: %v\n", v.Title)
    fmt.Printf("Link: %v\n", v.Link)
    fmt.Printf("Date: %v\n", v.PostDate)
}

Limit news results count

news, _ := awsnews.ThisMonth()
// Last 10 news items of the month
news.Last(10).Print()

Get news as JSON

news, _ := awsnews.ThisMonth()
json, jsonErr := news.JSON()
if jsonErr != nil {
    log.Fatal(err)
}
fmt.Println(string(json))

Get news as HTML

news, _ := awsnews.ThisMonth()
html := news.HTML()
fmt.Println(html)

Get news about a specific product

news, err := awsnews.Fetch(2019, 12)
if err != nil {
    fmt.Println(err)
} else {
    news.Filter([]string{"EKS", "ECS"}).Print()
}

Google Assistant

Development

Test

# Unit/Integration tests
make
# Get code coverage
make coverage

More Repositories

1

easy-soap-request

Small Node.js library to make SOAP requests easier
JavaScript
160
star
2

device-monitor-dashboard

Python script to generate html report of device online/offline status
Python
111
star
3

express-jwt

An example API for creating/verifying json web tokens
JavaScript
106
star
4

blockerized-dockchain

Because all problems are solvable with containers and blockchains
Python
86
star
5

k8s-label-rules-webhook

A validating admission webhook to ensure compliant labels in your k8s cluster
Go
53
star
6

terraform-provider-mcbroken

Base the count of your infrastucture resources on the current number of broken mcdonald's ice cream machines nationally or by a city of your choosing. Powered by https://mcbroken.com/
Go
30
star
7

go-geofence

A small library to detect if an IP address is close to yours or another of your choosing using https://ipbase.com
Go
18
star
8

pumpkin-pi

Raspberry pi project that controls jack-o-lantern via servo motor and PIR motion sensors
Go
18
star
9

caddy-geofence

A caddy module for IP geofencing your caddy web server using ipbase.com
Go
15
star
10

terraform-provider-mailform

A terraform provider to send physical mail via https://mailform.io
Go
14
star
11

web-link-tester

Flask App to scrape hrefs from websites and validate links
HTML
12
star
12

cv-notifier

Easily detect objects using computer vision and call configurable webhooks
Python
10
star
13

vault-plugin-secrets-jenkins

A plugin for Hashicorp Vault to create ephemeral users and API tokens for Jenkins CI
Go
8
star
14

local-puppet-dev

Docker setup for testing puppet manifests
Puppet
8
star
15

ava

A discord implementation of the famous ava bot
JavaScript
6
star
16

react-foaas-card

The most offensive of react components
JavaScript
6
star
17

go-mailform

A small library to send physical mail from your Go applications using https://mailform.io
Go
5
star
18

filter-object-array

Small Node.js library to filter an array of objects with an object
JavaScript
4
star
19

mcbroken-dashboard

Entry for digitalocean app platform hackathon
Go
4
star
20

google-home-aws-news

A webhook for google assistance integrations to provide the latest AWS news
Go
4
star
21

terraform-local-minio

Automatically install and create local buckets with public policies for testing
HCL
4
star
22

github-pr-exporter

A prometheus exporter for monitoring pull requests for specified users in the last X number of days.
Go
3
star
23

packer-aws-tomcat-template

A packer template to build AMI's with apache tomcat installed and systemd enabled. Based on Amazon linux.
HCL
3
star
24

witchonstephendrive.com

A home automation project to control my Halloween decorations
Go
2
star
25

href-scraper

ruby CLI to scrape hrefs from single webpages
Ruby
1
star
26

prometheus

Deployment of my personal prometheus instance
HCL
1
star
27

circa10a.github.io

Hosting of Portfolio
JavaScript
1
star
28

circa10a

My profile readme
1
star
29

l33tcrypto

Cryptography for the most l33t haxx0rs
Java
1
star