![How I Used Amazon Bedrock to Write, Schedule, and Submit My Tweets | by Allen Helton | Nov, 2023 How I Used Amazon Bedrock to Write, Schedule, and Submit My Tweets | by Allen Helton | Nov, 2023](https://techtoguide.com/wp-content/uploads/2023/11/How-I-Used-Amazon-Bedrock-to-Write-Schedule-and-Post-768x512.jpg)
[ad_1]
Now was time for the onerous half — determining the right way to programmatically schedule and ship social media posts. If you happen to observe me on LinkedIn or Twitter, you might need seen me submit about my struggles with this course of.
By a bunch of trials, errors, and discovery, I used to be ready to determine the right way to ship a tweet by way of the X API within a Lambda perform. As soon as I had that, I constructed the first iteration of my scheduler.
The method was triggered by an EventBridge occasion that kicked off a Step Operate workflow. The workflow would take a look at the occasion enter for a date and create a one-time EventBridge schedule. If the schedule already existed, it could replace the time and message. Then it could fireplace an occasion saying the submit was scheduled.
When the schedule would run, it could begin a separate Step Operate workflow that calls the “Ship Tweet” Lambda perform and sends a submit profitable occasion containing a hyperlink to the newly created tweet.
This labored nice, nevertheless it nonetheless required guide exercise. I had to supply a time within the occasion payload for it to work. The entire level of this was to bolster my laziness, in order that wouldn’t do.
I genuinely get pleasure from attempting out new AWS providers after they grow to be obtainable. Since Amazon Bedrock not too long ago went usually obtainable, I figured it was time to offer it a shot and see if it might clear up my issues for me.
I wanted to have some brains behind a scheduler. AI is the proper device for the job. I might present it some posting guidelines and get again a prompt time for the submit. So I grabbed a template from Serverless Land that had a deployable instance of utilizing Bedrock in a Lambda perform and commenced tinkering.
There have been a couple of guidelines I wished to include into my scheduler that ended up making an affect on the design:
- Submit at most one time a day
- Don’t submit on the weekends
- Submit when my viewers is awake and often on-line
- Area out posts for a similar weblog a minimal of 5 days aside
- Posts for a unique weblog will be scheduled on the following obtainable day
To do that, I used to be going to want to trace the schedules. Merely creating one-time EventBridge schedules wasn’t going to chop it as a result of I wanted to know what was scheduled when.
So I created a easy information mannequin in DynamoDB that allowed me to get all scheduled posts sooner or later sorted by date. When a tweet is posted, I take away the report from DynamoDB. Simple sufficient.
Entry Patterns
- Get social submit by id
- Get all social posts for a selected platform
| pk | sk | kind (GSI Hash Key) | kind (GSI Vary Key)| marketing campaign | | - - | - - | - - - - - - - - - - -| - - - - - - - - - - -| - - - - | | { postid1 } | "submit" | "twitter" | 2023–11–01T14:00:00 | { weblog identify 1} | | { postid2 }| "submit" | "twitter" | 2023–11–03T14:00:00 | { weblog identify 2 } | | { postid3 }| "submit" | "linkedin" | 2023–11–07T18:45:00 | { weblog identify 1 } |
I group social posts beneath a marketing campaign
property, which is a advertising time period for a set of associated duties. Every weblog submit is it is personal marketing campaign, so after I construct the immediate for the generative AI mannequin, I can do some preprocessing and modify the foundations earlier than I ask it to do its factor.
Now that I had the information mannequin, I needed to replace the prevailing workflows to create, replace, and delete the data after they have been run. This was dealt with by direct integrations to DynamoDB from my Step Operate workflow.
With the information mannequin absolutely in place, I might now present Bedrock with all the knowledge it wanted to find out a scheduled date. The workflow is formed up like this:
First, I’d load the submit schedule from DynamoDB. Then I formatted the immediate to incorporate my guidelines, details about the submit I wished to schedule, and a listing of all future posts. After the immediate is assembled I merely move that alongside to Bedrock utilizing the Claude V2 mannequin and get my advisable date because the output!
Right here’s an instance of the immediate I’m offering to Bedrock:
You're a grasp calender planner. I wish to schedule a social submit.
I would like you to offer me a time in UTC within the format of YYYY-MM-DDTHH:MM:SS.
My viewers is generally within the USA, some in Europe and is very technical.
Return ONLY the schedule date and nothing else.
Guidelines:
- The submit have to be no less than at some point after ${state.timestamp}
- Don't schedule a submit on the weekend.
- Just one submit is allowed to be scheduled a day
- Choose the following obtainable day sooner or later that matches the above guidelines until in any other case specified
- The scheduled time of day should range between excessive engagement instances within the morning and afternoon for the audience.
Schedule:
- 2023-11-01T14:00:00
- 2023-11-06T10:30:00
- 2023-11-07T18:45:00
Now that I’ve a generated date, the workflow can proceed the way it all the time did — create the one-time schedule and move alongside the message to be tweeted.
After all, I didn’t wish to take away performance. So I branched the logic within the workflow primarily based on the presence of the scheduleDate
property within the occasion. If it is offered, bypass the posting guidelines and schedule the tweet. If a date isn’t offered, use the foundations to provide you with the following obtainable date.
[ad_2]