https://github.com/harshitrv/tweet-lambda
a tweet lambda to post tweets on twitter using llm
https://github.com/harshitrv/tweet-lambda
aws aws-lambda lambda lambda-functions serverless
Last synced: about 2 months ago
JSON representation
a tweet lambda to post tweets on twitter using llm
- Host: GitHub
- URL: https://github.com/harshitrv/tweet-lambda
- Owner: HarshitRV
- License: mit
- Created: 2024-10-16T19:07:56.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T19:11:09.000Z (7 months ago)
- Last Synced: 2025-03-27T05:33:46.072Z (2 months ago)
- Topics: aws, aws-lambda, lambda, lambda-functions, serverless
- Language: TypeScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tweet Lambda
This AWS Lambda function generates and posts tweets using the `ai-tweet-gen` library and AWS Secrets Manager for secure storage of API keys.
## Project Structure
```sh
.
├── src
│ ├── handlers
│ │ └── tweet-lambda.ts
├── .gitignore
├── package.json
├── README.md
├── serverless.yml
├── yarn.lock
```## Prerequisites
- [Node.js 20.x](https://nodejs.org/en/download/package-manager)
- [AWS CLI](https://aws.amazon.com/cli/) configured with appropriate permissions
- [Serverless Framework](https://www.serverless.com/)## Setup
1. **Install Dependencies**
```sh
yarn install
```2. **Configure AWS Secrets Manager**
Create a new secret with the following key-value pairs:
- `TWITTER_APP_KEY`
- `TWITTER_APP_SECRET`
- `TWITTER_ACCESS_TOKEN`
- `TWITTER_ACCESS_SECRET`3. **Configure Serverless Framework**
Update the `provider` section in `serverless.yml` with your AWS account ID and region.
```yml
org:
app:
service:provider:
name: aws
runtime: nodejs20.x
stage: dev
region: ap-south-1iam:
role:
statements:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource:
-
functions:
hello:
handler: src/handlers/tweet-lambda.tweetHandler
events:
- http:
path: tweet
method: get
```## Deployment
```sh
serverless deploy
```## Usage
The Lambda function is triggered via API Gateway. It generates a tweet using the `generatePostGemini` function and posts it to Twitter using the `postToX` function.
### Example Request
```sh
curl -X GET https://.execute-api..amazonaws.com/dev/tweet
```### Example Response
```json
{
"statusCode": 200,
"body": "{\"message\":\"Tweet posted successfully!\"}"
}
```## License
This project is open source and available under the [MIT License](LICENSE).