Skip to content

Instantly share code, notes, and snippets.

@shamsway
Created January 21, 2020 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamsway/49e2a7f32a18cc9563c50cd1ba59f2ae to your computer and use it in GitHub Desktop.
Save shamsway/49e2a7f32a18cc9563c50cd1ba59f2ae to your computer and use it in GitHub Desktop.
YNAB Alert via AWS Lambda
from botocore.vendored import requests
import json
import boto3
def lambda_handler(event, context):
api_key = "[YOUR API KEY]"
category1 = "[YOUR BUDGET CATEGORY ID]"
url = "https://api.youneedabudget.com/v1/budgets/last-used/months/current/categories/{}".format(category1)
# Create an SNS client
sns = boto3.client('sns')
payload = ""
headers = {
'Accept': "application/json",
'Authorization': "Bearer {}".format(api_key),
'cache-control': "no-cache",
}
response = requests.request("GET", url, data=payload, headers=headers)
data = response.json()
name = data['data']['category']['name']
balance = data['data']['category']['balance'] / 1000
print("{}: ${:,.2f}\nTime to categorize your transactions!".format(name, balance))
# Publish a simple message to the specified SNS topic
response = sns.publish(
TopicArn='[YOUR TOPIC ARN]',
Message="{}: ${:,.2f}\nTime to categorize your transactions!".format(name, balance),
)
return {
'statusCode': 200,
'body': json.dumps("MessageId: {}\n{}: ${:,.2f}\nTime to categorize your transactions!".format(response['MessageId'], name, balance))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment