Dead simple AWS SQS to Twitter serverless speaker 🔈.
Publish message 💌 to SQS (FIFO), Lambda function will handle publishing it to Twitter. Automagically. 🎉
To be honest, my plan is to automate the tweet of certain information using this queue in multiple side projects.
As usual, I'm sharing this with you folks as I was not able to find equivalent in Github / Open source projects. I hope it could be useful to someone else.
Getting started
Update variables in
Makefileandtf/variables.tfaccording to your environment.
- type
maketo get started (help)
Requirements
- AWS Account
- Twitter API Keys
- Terraform
How to deploy on my AWS Account
make all(all-in-one command)
Manual - Under the hood (for Plumbers)
make artifacts(create S3 bucket)make package(create the zip artifact)make tf-init(to prepare terraform deployment)make tf-validate(optional) validate the IaC + FMTmake tf-plan(optional) Dry-Runmake tf-applyDeploy the infrastructure as code
nb: Terraform is using remote state on S3.
Setup Twitter secrets
How to get Twitter API Keys: https://developer.twitter.com/en/docs/basics/apps/guides/the-app-management-dashboard
After you've deployed the Terraform you will need to set Twitter API Keys manually to AWS Secret Manager using AWS console.
Set the following credentials in AWS Secret Manager:
- Consumer Key
- Consumer Key Secret
- Access Token
- Access Token Secret
How to publish a message
Using AWS Console
Using AWSCLI
aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue --message-body "Information about the largest city in Any Region." --delay-seconds 10 --message-attributes file://send-message.json
Doc: https://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html
Using Python (boto3)
import boto3 # Create SQS client sqs = boto3.client('sqs') queue_url = 'SQS_QUEUE_URL' # Send message to SQS queue response = sqs.send_message( QueueUrl=queue_url, DelaySeconds=10, MessageAttributes={ 'Title': { 'DataType': 'String', 'StringValue': 'The Whistler' }, 'Author': { 'DataType': 'String', 'StringValue': 'John Grisham' }, 'WeeksOn': { 'DataType': 'Number', 'StringValue': '6' } }, MessageBody=( 'Information about current NY Times fiction bestseller for ' 'week of 12/11/2016.' ) ) print(response['MessageId'])
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update the tests as appropriate. (just kidding, there is no test)
License
Credits
- AWS SQS
- AWS Lambda function
- AWS Secrets Manager
- Tweepy Python Library
