Skip to content

Commit

Permalink
Provide a Feast-specific webhook handler for Apple/iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwadeson committed Mar 13, 2024
1 parent 8036806 commit 7d45868
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
70 changes: 70 additions & 0 deletions cloudformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ Resources:
responses:
"200":
"description": "200 response (+)"
"feast/apple/pubsub":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FeastApplePubSubLambda.Arn}/invocations
consumes: [application/json]
produces: [application/json]
responses:
"200":
"description": "200 response"
"/healthcheck":
get:
responses:
Expand Down Expand Up @@ -589,6 +600,36 @@ Resources:
Stack: !Ref Stack
App: !Ref App

FeastApplePubSubLambda:
Type: AWS::Serverless::Function
Properties:
Handler: feast-apple-pubsub.handler
Runtime: nodejs20.x
CodeUri:
Bucket: !Ref DeployBucket
Key: !Sub ${Stack}/${Stage}/${App}-feast-apple-pubsub/feast-apple-pubsub.zip
FunctionName: !Sub ${App}-feastapplepubsub-${Stage}
Role: !GetAtt MobilePurchasesLambdasRole.Arn
Environment:
Variables:
Stage: !Ref Stage
Stack: !Ref Stack
App: !Ref App
Description: Records play store events
MemorySize: 128
Timeout: 29
Events:
PostApi:
Type: Api
Properties:
Path: "/feast/apple/pubsub"
Method: POST
RestApiId: !Ref MobilePuchasesApi
Tags:
Stage: !Ref Stage
Stack: !Ref Stack
App: !Ref App

GoogleSubscriptionsQueue:
Type: AWS::SQS::Queue
Properties:
Expand Down Expand Up @@ -840,6 +881,35 @@ Resources:
Threshold: 2
TreatMissingData: notBreaching

FeastApplePubsub5xxErrors:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled:
!FindInMap [StageVariables, !Ref Stage, AlarmActionsEnabled]
AlarmActions:
- Ref: AlarmTopic
OKActions:
- Ref: AlarmTopic
AlarmName: !Sub mobile-purchases-${Stage}-feast-apple-pubsub-check-errors
AlarmDescription: A HTTP request to the pubsub endpoint resulted in a 5XX error.
Dimensions:
- Name: ApiName
Value: !Sub ${App}-${Stage}
- Name: Method
Value: POST
- Name: Resource
Value: /feast/apple/pubsub
- Name: Stage
Value: !Ref Stage
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
MetricName: 5XXError
Namespace: AWS/ApiGateway
Period: 300
Statistic: Sum
Threshold: 2
TreatMissingData: notBreaching

UserSubscriptionsLambda:
Type: AWS::Serverless::Function
Properties:
Expand Down
6 changes: 6 additions & 0 deletions riff-raff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ deployments:
prependStackToCloudFormationStackName: false
dependencies: [mobile-purchases-cloudformation]

mobile-purchases-feast-apple-pubsub:
template: lambda
parameters:
functionNames: [mobile-purchases-feastapplepubsub-]
fileName: feast-apple-pubsub.zip

mobile-purchases-google-pubsub:
template: lambda
parameters:
Expand Down
6 changes: 6 additions & 0 deletions typescript/src/feast/pubsub/pubsub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {APIGatewayProxyEvent, APIGatewayProxyResult} from "aws-lambda";

export async function handler(request: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> {
console.log(`[34ef7aa3] ${JSON.stringify(request)}`)
return { statusCode: 200, body: JSON.stringify(request) }
}
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const getEntries = (env) => {
"export-subscription-events-table": "./typescript/src/export/exportEvents.ts",
"export-historical-data": "./typescript/src/export/exportHistoricalData.ts",
"apple-revalidate-receipts": "./typescript/src/revalidate-receipts/appleRevalidateReceipts.ts",
"feast-apple-pubsub": "./typescript/src/feast/pubsub/pubsub.ts"
};
return env.production ? entries : {
...entries,
Expand Down

0 comments on commit 7d45868

Please sign in to comment.