Skip to content

Commit

Permalink
fix: revert to cognito authorizer (#11426)
Browse files Browse the repository at this point in the history
* fix: revert to cognito authorizer

* fix: linting
  • Loading branch information
bashleigh authored Aug 29, 2024
1 parent e6c83ad commit 3abc68c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
45 changes: 22 additions & 23 deletions packages/deployment-service/cdk/lib/cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import {
LambdaRoute,
Queue,
createSecret,
createFunction,
} from '@reapit/ts-scripts/src/cdk'
import fs from 'fs/promises'
import { aws_sqs as sqs, aws_lambda, aws_apigateway } from 'aws-cdk-lib'
import { aws_sqs as sqs, aws_lambda } from 'aws-cdk-lib'

import { createLambda } from './create-lambda'
import { createS3Buckets } from './create-S3-bucket'
Expand Down Expand Up @@ -189,27 +188,27 @@ export const createStack = async () => {

env['CODEBUILD_PIPELINE_UPDATE_TOPIC_ARN'] = codebuildSnsTopic.topicArn

const authorizerLambda = createFunction(
stack,
'deployment-service-authorizer-lambda',
path.resolve(__dirname, '..', '..', 'dist', 'authorizer'),
'authorizer/index.handler',
{
ISSUERS: config.ISSUERS,
CLIENT_ID: config.COGNITO_CLIENT_ID,
CONNECT_USER_POOL: config.CONNECT_USER_POOL,
},
undefined,
undefined,
512,
aws_lambda.Runtime.NODEJS_18_X,
)
// const authorizerLambda = createFunction(
// stack,
// 'deployment-service-authorizer-lambda',
// path.resolve(__dirname, '..', '..', 'dist', 'authorizer'),
// 'authorizer/index.handler',
// {
// ISSUERS: config.ISSUERS,
// CLIENT_ID: config.COGNITO_CLIENT_ID,
// CONNECT_USER_POOL: config.CONNECT_USER_POOL,
// },
// undefined,
// undefined,
// 512,
// aws_lambda.Runtime.NODEJS_18_X,
// )

const authorizer = new aws_apigateway.RequestAuthorizer(stack, 'deployment-service-authorizer', {
handler: authorizerLambda,
identitySources: [aws_apigateway.IdentitySource.header('authorization')],
resultsCacheTtl: cdk.Duration.seconds(0),
})
// const authorizer = new aws_apigateway.RequestAuthorizer(stack, 'deployment-service-authorizer', {
// handler: authorizerLambda,
// identitySources: [aws_apigateway.IdentitySource.header('authorization')],
// resultsCacheTtl: cdk.Duration.seconds(0),
// })

for (const [name, options] of Object.entries(functionSetups)) {
const lambda = createLambda({
Expand All @@ -228,7 +227,7 @@ export const createStack = async () => {
if (options.queues) {
options.queues.forEach((queue) => addLambdaSQSTrigger(lambda, queue as Queue))
} else if (options.api) {
addLambdaToApi(stack, api, lambda, options.api.routes, undefined, options.api.authorizer ? authorizer : undefined)
addLambdaToApi(stack, api, lambda, options.api.routes, config.CONNECT_USER_POOL, undefined)
} else if (options.topic) {
addLambdaSNSTrigger(lambda, options.topic)
}
Expand Down
43 changes: 21 additions & 22 deletions packages/graphql-server/cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path'
import { execSync } from 'child_process'

import { createApi, createFunction, createBaseStack, output, addLambdaToApi } from '@reapit/ts-scripts/src/cdk'
import { Duration, aws_lambda, aws_apigateway } from 'aws-cdk-lib'

import config from './config.json'

Expand Down Expand Up @@ -44,29 +43,29 @@ const createStack = () => {
const lambdaFunction = createFunction(stack, 'graphql', entrypoint, handler, env)
const api = createApi(stack, 'api')

const authorizerLambda = createFunction(
stack,
'graphql-server-authorizer-lambda',
path.resolve(__dirname, 'dist', 'authorizer'),
'authorizer/index.handler',
{
ISSUERS: ISSUERS,
CLIENT_ID: config.COGNITO_CLIENT_ID,
CONNECT_USER_POOL: config.COGNITO_USERPOOL_ID,
},
undefined,
undefined,
undefined,
aws_lambda.Runtime.NODEJS_18_X,
)
// const authorizerLambda = createFunction(
// stack,
// 'graphql-server-authorizer-lambda',
// path.resolve(__dirname, 'dist', 'authorizer'),
// 'authorizer/index.handler',
// {
// ISSUERS: ISSUERS,
// CLIENT_ID: config.COGNITO_CLIENT_ID,
// CONNECT_USER_POOL: config.COGNITO_USERPOOL_ID,
// },
// undefined,
// undefined,
// undefined,
// aws_lambda.Runtime.NODEJS_18_X,
// )

const authorizer = new aws_apigateway.RequestAuthorizer(stack, 'graphql-server-authorizer', {
handler: authorizerLambda,
identitySources: [aws_apigateway.IdentitySource.header('authorization')],
resultsCacheTtl: Duration.seconds(0),
})
// const authorizer = new aws_apigateway.RequestAuthorizer(stack, 'graphql-server-authorizer', {
// handler: authorizerLambda,
// identitySources: [aws_apigateway.IdentitySource.header('authorization')],
// resultsCacheTtl: Duration.seconds(0),
// })

addLambdaToApi(stack, api, lambdaFunction, { path: '/{proxy+}', method: 'ANY' }, undefined, authorizer)
addLambdaToApi(stack, api, lambdaFunction, { path: '/{proxy+}', method: 'ANY' }, config.COGNITO_USERPOOL_ID)
output(stack, 'api-url', api.url)
}

Expand Down

0 comments on commit 3abc68c

Please sign in to comment.