From 333fa5bb8a639ed48400bf9f56e802914a95242a Mon Sep 17 00:00:00 2001 From: Tom Wadeson <3607811+tomwadeson@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:41:26 +0000 Subject: [PATCH] Provide a Feast-specific webhook handler for Apple/iOS --- cloudformation.yaml | 70 +++++++++++++++++++++++++++ riff-raff.yaml | 6 +++ typescript/src/feast/pubsub/pubsub.ts | 6 +++ webpack.config.js | 1 + 4 files changed, 83 insertions(+) create mode 100644 typescript/src/feast/pubsub/pubsub.ts diff --git a/cloudformation.yaml b/cloudformation.yaml index 16034562a..67f7d5325 100644 --- a/cloudformation.yaml +++ b/cloudformation.yaml @@ -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: @@ -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: @@ -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: diff --git a/riff-raff.yaml b/riff-raff.yaml index c29de591f..eb6f91873 100644 --- a/riff-raff.yaml +++ b/riff-raff.yaml @@ -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: diff --git a/typescript/src/feast/pubsub/pubsub.ts b/typescript/src/feast/pubsub/pubsub.ts new file mode 100644 index 000000000..e759f6da8 --- /dev/null +++ b/typescript/src/feast/pubsub/pubsub.ts @@ -0,0 +1,6 @@ +import {APIGatewayProxyEvent, APIGatewayProxyResult} from "aws-lambda"; + +export async function handler(request: APIGatewayProxyEvent): Promise { + console.log(`[34ef7aa3] ${JSON.stringify(request)}`) + return { statusCode: 200, body: JSON.stringify(request), isBase64Encoded: false } +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index b878a8886..3deb5faae 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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,