Lambda Twitter Blog Poster
Automagically post to Twitter timeline about new blog post using Go on AWS Lambda.
TL;DR Events are generated using webhooks - Gitlab in this case because that's where I store my site. On specific commit events (the commits contain a [NEW POST] block), a Twitter status is pushed to my timeline.
- Create a
serverless.env.ymlfile in the root of the project.
- Declare the following variables and values in the file -
secret: "<gitlab-token-header-secret>" apikey: "<twitter-consumer-api-key>" apisecret: "<twitter-consumer-secret-key>" accesstoken: "<twitter-app-access-token>" accesssecret: "<twitter-app-access-secret>" baseurl: "<url-of-blog>"
- Build the program using
make buildin the root of the project.
- To deploy, use
sls deploy -s <env-name>.
- Once deployed, copy the API Gateway URL printed on the console.
Create a webhook
Only GitLab is supported at the moment
- Navigate to the repo for which a webhook will be triggered.
- From the panel on the left, go to
Settings > Integrationsto create a new webhook.
- Paste the URL from the last section into the
URLfield and the secret from the
serverless.env.ymlfile in to the
- Click on
Add webhookto save.
Triggering the function
- To trigger a new post to Twitter on new post publishes, commit your new posts in the form -
[NEW POST] The title of the post permalink-of-the-post
Read the CONTRIBUTING guide for information.
Licensed under MIT. See LICENSE for more information.
Report a bug in issues.
Made with love in Kuala Lumpur, Malaysia by Riyadh Al Nur