Skip to content

Commit

Permalink
fix: set correct type for public URL events
Browse files Browse the repository at this point in the history
  • Loading branch information
sshelomentsev committed Feb 26, 2024
1 parent 82c053b commit 379ec65
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions mgmt-lambda/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
import { APIGatewayProxyEventV2WithRequestContext, APIGatewayEventRequestContextV2, Context } from 'aws-lambda'
import {
CloudFrontClient,
CreateInvalidationCommand,
Expand All @@ -17,7 +17,11 @@ import {

const REGION = 'us-east-1'

export async function handler(event: APIGatewayProxyEvent, ctx: Context) {
export async function handler(
event: APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>,
_: Context,
callback: any,
) {
console.info(JSON.stringify(event))

//TODO load data from AWS Secret
Expand All @@ -28,8 +32,26 @@ export async function handler(event: APIGatewayProxyEvent, ctx: Context) {
const lambdaFunctionName = userInput.LAMBDA_NAME
const cloudFrontDistrId = userInput.CF_DISTR_ID

const path = event.rawPath
console.info(`path = ${path}`)
if (path.startsWith('/update')) {
handleUpdate(cloudFrontDistrId, lambdaFunctionName)
} else if (path.startsWith('/status')) {
}

const okResp = {
statusCode: 200,
body: JSON.stringify({
message: 'OK',
}),
}

callback(null, okResp)
}

async function handleUpdate(cloudFrontDistributionId: string, lambdaFunctionName: string) {
console.info(`Going to upgrade Fingerprint Pro function association at CloudFront distbution.`)
console.info(`Lambda function: ${lambdaFunctionName}. CloudFront ID: ${cloudFrontDistrId}`)
console.info(`Lambda function: ${lambdaFunctionName}. CloudFront ID: ${cloudFrontDistributionId}`)

const latestFunctionArn = await getLambdaLatestVersionArn(lambdaFunctionName)
if (!latestFunctionArn) {
Expand All @@ -41,13 +63,10 @@ export async function handler(event: APIGatewayProxyEvent, ctx: Context) {
return publishJobSuccess()
}

updateCloudFrontConfig(ctx, cloudFrontDistrId, lambdaFunctionName, latestFunctionArn)

await publishJobSuccess()
updateCloudFrontConfig(cloudFrontDistributionId, lambdaFunctionName, latestFunctionArn)
}

async function updateCloudFrontConfig(
ctx: any,
cloudFrontDistributionId: string,
lambdaFunctionName: string,
latestFunctionArn: string,
Expand Down

0 comments on commit 379ec65

Please sign in to comment.