Skip to content

Commit

Permalink
fix: get yankee stuff to be deployable, add cloudformation for it (#79)
Browse files Browse the repository at this point in the history
* fix: get yankee stuff to be deployable, add cloudformation for it

* fix: add yankee function to resources

---------

Co-authored-by: JD Rudie <[email protected]>
  • Loading branch information
rudiejd and JD Rudie authored Mar 15, 2024
1 parent 9e5ee09 commit b6e22b2
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -x

if [[ -z "$MBTA_V2_API_KEY" || -z "$DD_API_KEY" ]]; then
echo "Must provide MBTA_V2_API_KEY and DD_API_KEY in environment" 1>&2
if [[ -z "$MBTA_V2_API_KEY" || -z "$DD_API_KEY" || -z "$YANKEE_API_KEY"]]; then
echo "Must provide MBTA_V2_API_KEY, YANKEE_API_KEY, and DD_API_KEY in environment" 1>&2
exit 1
fi

Expand All @@ -24,4 +24,4 @@ poetry run chalice package --stage prod --merge-template .chalice/resources.json
aws cloudformation package --template-file cfn/sam.json --s3-bucket $BUCKET --output-template-file cfn/packaged.yaml
aws cloudformation deploy --template-file cfn/packaged.yaml --stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset \
--parameter-overrides MbtaV2ApiKey=$MBTA_V2_API_KEY DDApiKey=$DD_API_KEY GitVersion=$GIT_VERSION DDTags=$DD_TAGS
--parameter-overrides MbtaV2ApiKey=$MBTA_V2_API_KEY DDApiKey=$DD_API_KEY YankeeApiKey=$YANKEE_API_KEY GitVersion=$GIT_VERSION DDTags=$DD_TAGS
4 changes: 4 additions & 0 deletions ingestor/.chalice/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
"update_time_predictions": {
"iam_policy_file": "policy-time-predictions.json",
"lambda_timeout": 300
},
"yankee": {
"iam_policy_file": "policy-yankee.json",
"lambda_timeout": 900
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions ingestor/.chalice/policy-yankee.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "arn:*:logs:*:*:*"
},
{
"Action": ["dynamodb:BatchWriteItem"],
"Effect": "Allow",
"Resource": [
"arn:aws:dynamodb:us-east-1:473352343756:table/ShuttleTravelTimes",
"arn:aws:dynamodb:us-east-1:473352343756:table/ShuttleTravelTimes"
]
},
{
"Action": ["dynamodb:Query"],
"Effect": "Allow",
"Resource": ["arn:aws:dynamodb:us-east-1:473352343756:table/ShuttleTravelTimes"]
},
{
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::tm-shuttle-positions",
"arn:aws:s3:::tm-shuttle-positions/*"
]
}
]
}
66 changes: 66 additions & 0 deletions ingestor/.chalice/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"Type": "String",
"Description": "MBTA Performance API Key"
},
"YankeeApiKey": {
"Type": "String",
"Description", "Yankee shuttle API key"
}
"DDApiKey": {
"Type": "String",
"Description": "Datadog API key."
Expand Down Expand Up @@ -36,6 +40,27 @@
}
}
},
"Yankee": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Environment": {
"Variables": {
"DD_API_KEY": {
"Ref": "DDApiKey"
},
"DD_VERSION": {
"Ref": "GitVersion"
},
"DD_TAGS": {
"Ref": "DDTags"
},
"YANKEE_API_KEY": {
"Ref": "YankeeApiKey"
}
}
}
}
},
"PopulateAggDeliveredTripMetrics": {
"Type": "AWS::Serverless::Function",
"Properties": {
Expand Down Expand Up @@ -559,6 +584,47 @@
}
]
}
},
"ShuttleTravelTimes": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "ShuttleTravelTimes",
"AttributeDefinitions": [
{
"AttributeName": "routeId",
"AttributeType": "S"
},
{
"AttributeName": "date",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "routeId",
"KeyType": "HASH"
},
{
"AttributeName": "date",
"KeyType": "RANGE"
}

],
"BillingMode": "PAY_PER_REQUEST",
"Tags": [
{
"Key": "service",
"Value": "t-performance-dash"
}
]
}
},
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": "tm-shuttle-positions"
}
}
}
}
4 changes: 2 additions & 2 deletions ingestor/chalicelib/yankee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import json
import boto3
from keys import YANKEE_API_KEY
from .keys import YANKEE_API_KEY
from botocore.exceptions import ClientError
from datetime import datetime
from tempfile import TemporaryDirectory
Expand Down Expand Up @@ -38,7 +38,7 @@ class ShuttleTravelTime:
# line of the trip (for now always line-shuttle)
line: str
# route of the trip e.g. Shuttle-AlewifeParkSt
route: str
routeId: str
date: datetime
# distance in miles of the trip
distance_miles: float
Expand Down

0 comments on commit b6e22b2

Please sign in to comment.