Skip to content

Commit

Permalink
WIP: make bootstrapping-lambda accept direct invocations (from octopu…
Browse files Browse the repository at this point in the history
…s-api)
  • Loading branch information
twrichards committed Jun 12, 2024
1 parent 849690c commit 7116353
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bootstrapping-lambda/src/octopusImagingHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type ImagingCallFromOctopus = {};

export const handleImagingCallFromOctopus = async (
detail: ImagingCallFromOctopus
) => {
console.log("Handling imaging call from Octopus", detail);
return {};
};
18 changes: 15 additions & 3 deletions bootstrapping-lambda/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
} from "./middleware/auth-middleware";

import { getMetrics } from "./reporting/reportingServiceClient";
import { ImagingUpdateFromOctopus } from "shared/octopusImaging";
import { handleImagingCallFromOctopus } from "./octopusImagingHandler";

const s3 = new S3(standardAwsConfig);

Expand Down Expand Up @@ -162,8 +164,18 @@ if (IS_RUNNING_LOCALLY) {
const PORT = 3030;
server.listen(PORT, () => console.log(`Listening on port ${PORT}`));
} else {
exports.handler = (
event: lambda.APIGatewayProxyEvent,
exports.handler = async (
payload: lambda.APIGatewayProxyEvent | ImagingUpdateFromOctopus,
context: lambda.Context
) => proxy(createServer(server), event, context);
) => {
if ("httpMethod" in payload) {
// from API Gateway
return proxy(createServer(server), payload, context);
} else if ("pinboardItemId" in payload) {
// imaging update from octopus-api
return await handleImagingCallFromOctopus(payload);
}
console.error("unexpected payload", payload);
throw new Error("Not implemented");
};
}
9 changes: 9 additions & 0 deletions cdk/lib/__snapshots__/stack.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Object {
"gu:cdk:version": "49.5.0",
},
"Outputs": Object {
"BootstrappingLambdaFunctionName": Object {
"Description": "pinboard-bootstrapping-lambda-api function name",
"Export": Object {
"Name": "pinboard-bootstrapping-lambda-api-function-name",
},
"Value": Object {
"Ref": "pinboardbootstrappinglambdaD2C487DA",
},
},
"pinboardbootstrappinglambdaapiEndpoint4DE1E032": Object {
"Value": Object {
"Fn::Join": Array [
Expand Down
6 changes: 6 additions & 0 deletions cdk/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,5 +740,11 @@ export class PinBoardStack extends GuStack {
description: `${bootstrappingLambdaApiBaseName}-hostname`,
value: `${bootstrappingApiDomainName.domainNameAliasDomainName}`,
});

new CfnOutput(this, `BootstrappingLambdaFunctionName`, {
exportName: `${bootstrappingLambdaApiBaseName}-function-name`,
description: `${bootstrappingLambdaApiBaseName} function name`,
value: `${bootstrappingLambdaFunction.functionName}`,
});
}
}

0 comments on commit 7116353

Please sign in to comment.