Code Monkey home page Code Monkey logo

plotly-to-slack-lambda-function's Introduction

plotlyImageToSlack

plotlyImageToSlack downloads the image of a Plotly chart and messages it to you via Slack. plotlyImageToSlack is intended to be run as an AWS Lambda function.

Note: at the time of creation Plotly image previews did not load in Slack.

Pre-reqs

  • boto3: We assume that you are familiar with using AWS's boto3 Python client, and that you have followed AWS's instructions to configure your AWS credentials.

  • Plotly: You will need a Plotly account and API token. If you are not already a Plotly user you can test this function with graphs from their public feed

  • Slack: You will need a Slack channel where you would like to post your Plotly images, and a token that has permissions to post to this channel. We suggest using the token from a bot user.

Quickstart

Run pip install -r requirements.txt to install development requirements. Once you've followed the steps in the previous section, run the following code to create or fetch an IAM role, and create a Lambda function:

python create_lambda_function.py \
  --plotly-api-token <YOUR PLOTLY API TOKEN> \
  --plotly-username <YOUR PLOTLY USERNAME> \
  --slack-channel <'#channel' or '@username' on SLACK> \
  --slack-token <SLACK BOT TOKEN>

You can test your function by running:

from aws_clients import LambdaClient

lambda_client = LambdaClient()
lambda_client.invoke("https://plot.ly/~matlab_user_guide/436")

If the function was configured correctly, you should receive a slack message with a Plotly image.

Debugging

You can debug, change environment variables, and test via the AWS Console. test_event.json is a test event that you can copy-paste into the AWS Lambda console.

Interested in Making Edits?

You'll find util functions for the lambda and iam boto clients in aws_clients.py, and a script for re-packaging the Lambda function and its dependencies in zip_for_lambda.sh.

To learn more about packaging and deploying functions to Lambda, read my blog post AWS Lambda Functions Made Easy.

plotly-to-slack-lambda-function's People

Contributors

alexandraj777 avatar

Watchers

James Cloos 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.