Giter VIP home page Giter VIP logo

genericslackbotkitfargate's Introduction

genericSlackBotkitFargate

  • Based on Botkit for Slack
  • Real Time Messaging (RTM via outbound WebSocket, not inbound HTTP ports as with events API)
  • Docker / AWS Fargate and Secrets Manager via AWS CLI and CloudFormation

Before You Begin

Make sure you have the following in place

Prerequisites Verification

  • Functional AWS CLI (likely an administrative account with API access)
# Note: Creating AWS credentials - https://serverless.com/framework/docs/providers/aws/guide/credentials/
pip install awscli
aws --version
aws configure
aws iam get-user
# Note: Creating AWS credentials - https://serverless.com/framework/docs/providers/aws/guide/credentials/
# For macOS:
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli

# For Linux systems:
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli

# For Windows systems using Windows PowerShell (as an administrator):
New-Item ‘C:\Program Files\Amazon\ECSCLI’ -type directory
Invoke-WebRequest -OutFile ‘C:\Program Files\Amazon\ECSCLI\ecs-cli.exe’ https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe
# Note: Add C:\Program Files\Amazon\ECSCLI to the Windows PATH and then restart PowerShell


# Verify the CLI version (all OSes):
ecs-cli --version

# REF: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_Configuration.html

Deployment

Get Started

Clone this repository:

git clone https://github.com/ernestgwilsonii/genericSlackBotkitFargate.git

Install:

cd genericSlackBotkitFargate
npm install

Choose an AWS region (make sure Fargate is available)

  • Set AWS region
# This kit assumes and requires BASH shell (on any OS)
bash
export AWS_DEFAULT_REGION=us-east-1
echo $AWS_DEFAULT_REGION
  • Set Slack bot name
export IMAGE_REPO_NAME=yourbotnamegoeshere
echo $IMAGE_REPO_NAME

Define the AWS_DEFAULT_REGION and AWS_SECRETS_MANAGER_ID for AWS Fargate

  • Edit .env
vi .env
AWS_DEFAULT_REGION=us-east-1
AWS_SECRETS_MANAGER_ID=yourbotnamegoeshere

Amazon Secrets Manager

  • Edit aws/secrets.json file for use with AWS Secrets Manager
vi aws/secrets.json
{
    "slackToken": "xoxb-NNNNNNNNNNN-NNNNNNNNNNNN-XXXXXXXXXXXXXXXXXXXXXXXX"
}
  • Create a new secret in the AWS Secret Manager
aws secretsmanager --region $AWS_DEFAULT_REGION create-secret --name $IMAGE_REPO_NAME \
    --description "Slack Botkit Secrets" \
    --secret-string file://aws/secrets.json

# NOTE: Secrets can be used with ECS Fargate or Lambda and/or other
#       AWS services instead of and/or in addition to environment variables
  • Verify that the secret was created successfully
aws secretsmanager --region $AWS_DEFAULT_REGION get-secret-value --secret-id $IMAGE_REPO_NAME

Amazon Elastic Container Registry

  • Create an Amazon Elastic Container Registry (ECR) for the Docker container
aws ecr create-repository --repository-name $IMAGE_REPO_NAME
aws ecr describe-repositories --repository-name $IMAGE_REPO_NAME
  • Get (and set) your AWS Account ID value
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
echo $AWS_ACCOUNT_ID
  • Build Docker Image
# Set build tag
export IMAGE_TAG=latest
echo $IMAGE_TAG

# Build container
docker build --no-cache -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG .
#docker images
#docker system prune --all
  • Log-in to AWS ECR
export AWS_ECR_LOGIN=$(aws ecr get-login --no-include-email) && $AWS_ECR_LOGIN
  • Upload docker container to AWS ECR
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

Amazon Elastic Container Service

  • Deploy AWS CloudFormation stack via template
# Deploy
aws cloudformation deploy --stack-name=$IMAGE_REPO_NAME --template-file=aws/chatops-stack.yml --parameter-overrides ServiceName=$IMAGE_REPO_NAME ImageTag=$IMAGE_TAG --capabilities=CAPABILITY_IAM

# List
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE
#aws cloudformation delete-stack --stack-name $IMAGE_REPO_NAME

Testing Locally

# Set Slack bot token
export slackToken=xoxb-NNNNNNNNNNN-NNNNNNNNNNNN-XXXXXXXXXXXXXXXXXXXXXXXX
echo $slackToken

# Run the Docker container
docker run -it --rm --name $IMAGE_REPO_NAME -e slackToken=$slackToken $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

# NOTES:
#/root/.local/bin/aws --version
#/root/.local/bin/aws configure

genericslackbotkitfargate's People

Contributors

ernestgwilsonii avatar

Watchers

 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.