A Google Cloud Function that runs every day to send birthday wishes to Yalies. Uses Gemini API for poem generation and AWS SES for sending emails.
This project was originally AWS Lambda + OpenAI. I was able to use AI tools to convert it over to Google Cloud Functions + Gemini. So excuse the AI slop 😅
Old code is still available in
/lambda, but all production code runs frombirthday-bot-cloud-functionnow.
Yale's new ValiMail policy requires your SES account to be DKIM-verified.
- Put your AWS credentials file in
birthday-bot-cloud-function/aws-credentials.json
-
Create a GCP Project
- Go to Google Cloud Console
- Create a new project or select an existing one.
-
Enable APIs
- Enable the Cloud Functions API.
- Enable the Gmail API (if using Gmail SMTP).
- Enable the Gemini API (Generative Language API).
-
Configure Secrets
- Copy
birthday-bot-cloud-function/secrets.js.templatetosecrets.jsand fill in:YALIES_API_KEY: Your Yalies API keyGEMINI_API_KEY: Your Gemini API key (get it here)GMAIL_USER: Gmail address to send fromGMAIL_PASS: App password (see Google App Passwords)
- Copy
-
Create a Service Account
- To create a service account email, follow these steps:
- Go to the Google Cloud Console.
- Select your project.
- Navigate to IAM & Admin > Service Accounts.
- Click on Create Service Account.
- Enter a name and description for the service account.
- Click Create.
- Assign the role Cloud Functions Invoker to the service account.
- Click Done.
- After creating the service account, click on it to view details.
- Under the Keys tab, click Add Key > Create New Key.
- Choose JSON and click Create. This will download a JSON file with your service account credentials.
- Make sure to keep this JSON file secure, as it contains sensitive information.
- To create a service account email, follow these steps:
-
Install dependencies
cd birthday-bot-cloud-function && npm install
-
Deploy the Cloud Function
- Run:
gcloud functions deploy birthdayBotGCF \ --runtime=nodejs20 \ --trigger-http \ --entry-point=birthdayBotGCF \ --region=us-central1 \ --service-account=<YOUR_SERVICE_ACCOUNT_EMAIL> \
- Adjust region/runtime as needed.
- Grant the Cloud Scheduler service account permission to invoke the function:
gcloud functions add-iam-policy-binding birthdayBotGCF \ --member=serviceAccount:<CLOUD_SCHEDULER_SERVICE_ACCOUNT_EMAIL> \ --role=roles/cloudfunctions.invoker
- Run:
-
Set up a timer/cron (Cloud Scheduler)
- Go to Cloud Scheduler
- Create a new job:
- Frequency:
0 9 * * *(every day at 9am) - Target: HTTP
- URL: Your function's HTTPS endpoint
- HTTP Method: POST
- Authentication: Select "Add OIDC token"
- Service account email: Use the same service account email you created above (
<CLOUD_SCHEDULER_SERVICE_ACCOUNT_EMAIL>) - Audience: Use the default or set to your function's URL
- Service account email: Use the same service account email you created above (
- (Optionally) Add other settings as needed
- Frequency: