bZapp

package module
v0.0.0-...-013d6bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 26 Imported by: 0

README

bZapp

bZapp is a slack app to facilitate a standup meeting in a work from home or remote workplace. It simulates a whiteboard with today and tomorrow's meetings or events and lists teams goals.

bZapp whiteboard

Quick Start

This project uses :

Install the CLI tools and Docker CE

$ brew install awscli go node python@2 watchexec
$ pip2 install aws-sam-cli
$ open https://store.docker.com/search?type=edition&offering=community
We may want to upgrade existing tools...  
$ brew upgrade awscli go node python@2 watchexec
$ pip2 install --upgrade aws-sam-cli
We may also want to configure the AWS CLI with IAM keys to develop and deploy our application...  

Follow the Creating an IAM User in Your AWS Account doc to create a IAM user with programmatic access. Call the user admin and attach the "Administrator Access" policy for now.

Then configure the CLI. Here we are creating a new profile that we can switch to with export AWS_PROFILE=bZapp. This will help us isolate our experiments from other AWS work.

Configure an AWS profile with keys and switch to the profile:

$ aws configure --profile bZapp
AWS Access Key ID [None]: AKIA................
AWS Secret Access Key [None]: PQN4CWZXXbJEgnrom2fP0Z+z................
Default region name [None]: us-east-1
Default output format [None]: json

$ export AWS_PROFILE=bZapp
$ aws iam get-user
{
    "User": {
        "Path": "/",
        "UserName": "Admin",
        "UserId": "**************",
        "Arn": "arn:aws:iam::*************:user/Admin",
        "CreateDate": "20**-**-88T23:11:39+00:00"
    }
}
Get the App

We start by getting and testing the github.com/dctid/bZapp.

$ git clone https://github.com/dctid/bZapp.git
$ cd ~/bZapp

$ make test
go test -v ./...
go: finding github.com/aws/aws-xray-sdk-go v1.0.0-rc.8
go: finding github.com/aws/aws-lambda-go v1.6.0
go: finding github.com/aws/aws-sdk-go v1.15.49
...
=== RUN   TestInteraction/open_edit_events
--- PASS: TestInteraction/open_edit_events (0.00s)
...
ok     github.com/dctid/bZapp      0.014s
PASS

This gives us confidence in our Go environment.

Develop the App

We can then build the app and start a development server:

$ make app
cd ./handlers/dashboard && GOOS=linux go build...
2018/02/25 08:03:12 Connected to Docker 1.35
2018/02/16 07:40:32 Fetching lambci/lambda:go1.x image for go1.x runtime...

Mounting handler (go1.x) at http://127.0.0.1:3000/users/{id} [DELETE]
Mounting handler (go1.x) at http://127.0.0.1:3000/users/{id} [PUT]
Mounting handler (go1.x) at http://127.0.0.1:3000/users/{id} [GET]
Mounting handler (go1.x) at http://127.0.0.1:3000/ [GET]
Mounting handler (go1.x) at http://127.0.0.1:3000/users [POST]

Now we can access our HTTP functions on port 3000:

$ curl http://localhost:3000
<html><body><h1>bZapp dashboard</h1></body></html>

We can also invoke a function directly:

$ echo '{}' | sam local invoke DashboardFunction
...
START RequestId: b69240d1-66a6-1dfd-89d1-296bdee4081c Version: $LATEST
END RequestId: b69240d1-66a6-1dfd-89d1-296bdee4081c
REPORT RequestId: b69240d1-66a6-1dfd-89d1-296bdee4081c  Init Duration: 433.77 ms        Duration: 4.00 ms       Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 30 MB  

{"statusCode":200,"headers":{"Content-Type":"text/html"},"body":"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003ebZapp dashboard\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\n"}

Note: if you see No AWS credentials found. Missing credentials may lead to slow startup..., review aws configure list and your AWS_PROFILE env var.

This gives us confidence in our development environment.

The local environment also starts a docker image that creates a local DynamDB instance.

To shutdown this DynamoDB instance when done developing locally:

$ make dynamo-stop

docker-compose down
Removing dynamodb ... done
Removing network bzapp_default
Deploy the App

Now we can package and deploy the app:

$ make deploy
make_bucket: pkgs-*************-us-east-1
Uploading to ********************  3018471 / 3018471.0  (100.00%)
Waiting for changeset to be created
Waiting for stack create/update to complete
Successfully created/updated stack - bZapp

ApiUrl	https://********.execute-api.us-east-1.amazonaws.com/Prod

Now we can access our HTTP functions on AWS:

$ curl https://********.execute-api.us-east-1.amazonaws.com/Prod
<html><body><h1>bZapp dashboard</h1></body></html>

Look at that speedy 11 ms duration! Go is faster than the minimum billing duration of 100 ms.

This gives us confidence in our production environment.

Configuring Slack

TBD

Contributing

Find a bug or see a way to improve the project? Open an issue.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	APIGateway = NewAPIGateway()
	DynamoDB   = NewDynamoDB()
	KMS        = NewKMS()
	Lambda     = NewLambda()
	S3         = NewS3()
	SNS        = NewSNS()
)

AWS Clients that can be mocked for testing

Functions

func Dashboard

Dashboard returns a dashboard HTML page

func Get

func Get(url string, headers http.Header) (*http.Response, error)

Post sends a post request to the URL with the body

func GetModelFromDb

func GetModelFromDb(ctx aws.Context, channel string) (*model.Model, error)

func JsonHeaders

func JsonHeaders() map[string]string

func NewAPIGateway

func NewAPIGateway() *apigateway.APIGateway

NewAPIGateway is an xray instrumented APIGateway client

func NewLambda

func NewLambda() *lambda.Lambda

NewLambda is an xray instrumented Lambda client

func NewS3

func NewS3() *s3.S3

NewS3 is an xray instrumented S3 client

func NewSNS

func NewSNS() *sns.SNS

NewSNS is an xray instrumented SNS client

func Post

func Post(url string, headers http.Header, body interface{}) (*http.Response, error)

Post sends a post request to the URL with the body

func SaveModel

func SaveModel(ctx aws.Context, channel string, currentModel *model.Model) error

Types

type DynamoDBAPI

type DynamoDBAPI interface {
	DeleteItemWithContext(ctx aws.Context, input *dynamodb.DeleteItemInput, opts ...request.Option) (*dynamodb.DeleteItemOutput, error)
	GetItemWithContext(ctx aws.Context, input *dynamodb.GetItemInput, opts ...request.Option) (*dynamodb.GetItemOutput, error)
	PutItemWithContext(ctx aws.Context, input *dynamodb.PutItemInput, opts ...request.Option) (*dynamodb.PutItemOutput, error)
}

DynamoDBAPI is a subset of dynamodbiface.DynamoDBAPI

func NewDynamoDB

func NewDynamoDB() DynamoDBAPI

NewDynamoDB is an xray instrumented DynamoDB client

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface

var (
	Client HTTPClient
)

type HandlerAPIGateway

HandlerAPIGateway is an API Gateway Proxy Request handler function

func NotifyAPIGateway

func NotifyAPIGateway(h HandlerAPIGateway) HandlerAPIGateway

NotifyAPIGateway wraps a handler func and sends an SNS notification on error

func VerifyRequestInterceptor

func VerifyRequestInterceptor(h HandlerAPIGateway) HandlerAPIGateway

type HandlerCloudWatch

type HandlerCloudWatch func(context.Context, events.CloudWatchEvent) error

HandlerCloudWatch is a CloudWatchEvent handler function

type KMSAPI

type KMSAPI interface {
	DecryptWithContext(ctx aws.Context, input *kms.DecryptInput, opts ...request.Option) (*kms.DecryptOutput, error)
	EncryptWithContext(ctx aws.Context, input *kms.EncryptInput, opts ...request.Option) (*kms.EncryptOutput, error)
}

KMSAPI is a subset of kmsiface.KMSAPI

func NewKMS

func NewKMS() KMSAPI

NewKMS is an xray instrumented KMS client

Directories

Path Synopsis
handlers

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL