Complete guide for deploying the Twitter Repost Agent to AWS Lambda.
- AWS CLI configured with appropriate credentials
- Twitter Developer account with app created
- DeepSeek API key
- Node.js 18.x or higher installed locally
- Go to Twitter Developer Portal
- Navigate to your app → Settings → User authentication settings
- Set App permissions to "Read and Write"
- Save and go to Keys and tokens tab
- Generate/regenerate these credentials:
- API Key (Consumer Key)
- API Secret (Consumer Secret)
- Bearer Token
- Access Token (generate AFTER setting Read/Write permissions)
- Access Token Secret
Important: Access tokens inherit permissions at generation time. Generate them only after setting "Read and Write" permissions.
- Go to AWS Secrets Manager → Store a new secret
- Select "Other type of secret"
- Add key-value pairs:
{ "twitter_api_key": "your_api_key", "twitter_api_secret": "your_api_secret", "twitter_access_token": "your_access_token", "twitter_access_token_secret": "your_access_token_secret", "twitter_bearer": "your_bearer_token", "deepseek_api_key": "your_deepseek_api_key" } - Secret name:
TwitterRepostSecrets - Leave other settings as default and create
- Go to DynamoDB → Create table
- Table name:
RepostedTweets - Partition key:
tweetId(Type: String) - Table settings: On-demand capacity mode
- Click Create table
- After creation, go to table → Additional settings → Time to Live (TTL)
- Click Enable TTL
- TTL attribute name:
ttl - Click Enable
In your project directory:
# Install dependencies
npm install
# Create deployment zip
zip -r function.zip index.js package.json package-lock.json node_modules/- Go to AWS Lambda → Create function
- Select "Author from scratch"
- Function name:
TwitterRepostAgent - Runtime: Node.js 22.x
- Click Create function
- In the Lambda function page, click "Upload from" → ".zip file"
- Select your
function.zip - Click Save
- Go to Configuration tab → Environment variables → Edit
- Add variables:
- Key:
SECRET_NAME→ Value:TwitterRepostSecrets - Key:
POSTED_TWEETS_TABLE→ Value:RepostedTweets
- Key:
- Click Save
- Go to Configuration → General configuration → Edit
- Change Timeout to
120seconds (2 minutes) - Click Save
- Go to Configuration → Permissions
- Click on the Role name (opens IAM in new tab)
- Click Add permissions → Attach policies
- Search and attach these policies:
SecretsManagerReadWriteAmazonDynamoDBFullAccess
- Click Add permissions
- Go to Test tab
- Click Create new event
- Event name:
TestRepost - Leave JSON as default
{} - Click Save
- Click Test to execute
Expected success response:
{
"statusCode": 200,
"body": "{\"message\":\"Quoted tweet https://twitter.com/...\",\"comment\":\"...\",\"result\":{...}}"
}Common errors:
429: Rate limit - wait 5-10 minutes before testing again403/401: Check Twitter app permissions are "Read and Write"500: Check CloudWatch logs for detailed error
- Go to Configuration → Triggers → Add trigger
- Select "EventBridge (CloudWatch Events)"
- Create a new rule
- Rule name:
DailyRepostTrigger - Rule type: Schedule expression
- Schedule expression:
cron(0 9 * * ? *)(daily at 9 AM UTC) - Click Add
Other schedule examples:
- Every 12 hours:
cron(0 0,12 * * ? *) - Twice daily (9 AM & 9 PM UTC):
cron(0 9,21 * * ? *) - Every 6 hours:
cron(0 */6 * * ? *)
- Check the test execution succeeded
- Verify the quote tweet was posted on Twitter
- Check DynamoDB table has a new entry with the posted tweet ID
- Go to Monitor tab → View CloudWatch logs to see execution details
Access logs: Lambda → Monitor → View CloudWatch logs
Key log messages:
- ✅
Successfully posted quote tweet: [comment] ⚠️ AI comment generation failed- Using fallback comment- ℹ️
No new tweets to quote- All recent tweets already reposted
When you make code changes:
# Update code locally
# Recreate zip
zip -r function.zip index.js package.json package-lock.json node_modules/
# Upload via Lambda console or AWS CLI
aws lambda update-function-code \
--function-name TwitterRepostAgent \
--zip-file fileb://function.zipTo remove all resources:
- Delete Lambda function
- Delete EventBridge rule
- Delete DynamoDB table
- Delete Secrets Manager secret
- Delete IAM role (auto-created by Lambda)
Deployment complete! Your bot will now automatically repost the best content from your target account daily.