Giter VIP home page Giter VIP logo

neuralyzer's Introduction

neuralyzer

Table of Contents

A Go based Amazon Lambda function to periodically delete stale tweets, complete with:

Heavily inspired by ephemeral, by @vickylai. All of the tweet deleting functionality was redone from scratch as an exercise to get familiar with Go and the AWS SDK for Go. Also, it was a good excuse to take a closer look at SAM.

Configuration

All of the application configuration is provided through a mixture SSM parameters and environment variables. The sensitive ones come through the former, and the rest through the latter.

SSM parameters

  • /neuralyzer/twitter/accessToken: Twitter API access token
  • /neuralyzer/twitter/accessTokenSecret: Twitter API access token secret
  • /neuralyzer/twitter/consumerKey: Twitter API consumer key
  • /neuralyzer/twitter/consumerKeySecret: Twitter API consumer key secret

Environment variables

  • NEURALYZER_TWEET_AGE_THRESHOLD: Tweet age threshold for deleting tweets (default: 2190h)

Testing

Once the SSM parameters above exist, install sam and its prerequisites (Docker, Python 2.7).

Note: Be careful not to accidentally delete all of your tweets by invoking the function locally!

Next, use the testacc target of the Makefile to build a Linux compatible binary and execute it within a container image that mimics the Amazon Lambda execution environment for Go.

$ make testacc -e AWS_PROFILE=personal
GOOS=linux go build -o main main.go
sam local generate-event schedule | sam local invoke NeuralyzerFunction
2018-05-29 23:05:59 Reading invoke payload from stdin (you can also pass it from file with --event)
2018-05-29 23:06:00 Invoking main (go1.x)
2018-05-29 23:06:00 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:go1.x Docker container image......
2018-05-29 23:06:00 Mounting /Users/hector/.go/src/github.com/hectcastro/neuralyzer as /var/task:ro inside runtime container
START RequestId: 747fc7fe-5471-13ca-a7ae-8cbeb0335031 Version: $LATEST
2018/05/30 03:06:17 ID [1001653560956858368] Hi, there.
END RequestId: 747fc7fe-5471-13ca-a7ae-8cbeb0335031
REPORT RequestId: 747fc7fe-5471-13ca-a7ae-8cbeb0335031  Duration: 479.12 ms     Billed Duration: 500 ms Memory Size: 128 MB     Max Memory Used: 14 MB
null

Deployment

The deployment process works in two phases:

  1. Package the function and upload it to S3
  2. Deploy the function and its supporting infrastructure (referencing the artifact above)

Both of these steps are handled by the sam CLI, which seems to mostly wrap the aws cloudformation CLI.

First, use the package target of the Makefile to upload the binary to S3 and reference it in a newly created packaged.yaml CloudFormation configuration.

$ make package -e AWS_PROFILE=personal
GOOS=linux go build -o main main.go
sam package --s3-bucket neuralyzer-global-config-us-east-1 --template-file template.yaml --output-template-file packaged.yaml                                                    
Uploading to 7001c68762c2fcda61de373e0a30563d  29187040 / 29187040.0  (100.00%)
Successfully packaged artifacts and wrote output template to file packaged.yaml.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file packaged.yaml --stack-name <YOUR STACK NAME>

Lastly, use the deploy target of the Makefile to apply the packaged.yaml CloudFormation configuration.

$ make deploy -e AWS_PROFILE=personal 
sam deploy --template-file packaged.yaml --stack-name Neuralyzer --capabilities CAPABILITY_IAM

Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - Neuralyzer

neuralyzer's People

Contributors

hectcastro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.