diff --git a/config/constants.ts b/config/constants.ts index 865d3f401..cc98f88e7 100644 --- a/config/constants.ts +++ b/config/constants.ts @@ -1,4 +1,6 @@ +import { RemovalPolicy } from 'aws-cdk-lib'; import { VpcLookupOptions } from 'aws-cdk-lib/aws-ec2'; +import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import path from 'path'; export enum AppStage { @@ -35,15 +37,35 @@ export const vpcProps: VpcLookupOptions = { }; // upstream infra: cognito -export const cognitoUserPoolIdParameterName = '/data_portal/client/cog_user_pool_id'; export const cognitoPortalAppClientIdParameterName = '/data_portal/client/data2/cog_app_client_id_stage'; -export const cognitoStatusPageAppClientIdParameterName = - '/data_portal/status_page/cog_app_client_id_stage'; -export const cognitoApiGatewayProps = { - cognitoUserPoolIdParameterName: cognitoUserPoolIdParameterName, - cognitoPortalAppClientIdParameterName: cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName: cognitoStatusPageAppClientIdParameterName, +export const cognitoUserPoolIdParameterName = '/data_portal/client/cog_user_pool_id'; +export const logsApiGatewayConfig = { + [AppStage.BETA]: { + retention: RetentionDays.TWO_WEEKS, + removalPolicy: RemovalPolicy.DESTROY, + }, + [AppStage.GAMMA]: { + retention: RetentionDays.TWO_WEEKS, + removalPolicy: RemovalPolicy.DESTROY, + }, + [AppStage.PROD]: { + retention: RetentionDays.TWO_YEARS, + removalPolicy: RemovalPolicy.RETAIN, + }, +}; +export const corsAllowOrigins = { + [AppStage.BETA]: ['https://orcaui.dev.umccr.org'], + [AppStage.GAMMA]: ['https://orcaui.stg.umccr.org'], + [AppStage.PROD]: ['https://orcaui.prod.umccr.org', 'https://orcaui.umccr.org'], +}; +export const cognitoApiGatewayConfig = { + region, + cognitoUserPoolIdParameterName, + cognitoClientIdParameterNameArray: [ + cognitoPortalAppClientIdParameterName, // portal - TokenServiceStack + '/orcaui/cog_app_client_id_stage', // orcaui - https://github.com/umccr/orca-ui + ], }; export const oncoanalyserBucket: Record = { @@ -153,9 +175,6 @@ export const bclconvertInteropQcDynamoDbTableSSMArn = path.join( ); // Stateless - -export const corsAllowOrigins = ['*']; - export const bclconvertInteropQcIcav2PipelineWorkflowName = 'bclconvert-interop-qc'; export const bclconvertInteropQcIcav2PipelineWorkflowTypeVersion = '1.3.1--1.21'; export const bclconvertInteropQcIcav2ServiceVersion = '2024.07.01'; diff --git a/config/stacks/fileManager.ts b/config/stacks/fileManager.ts index 45deafe73..79085dcbe 100644 --- a/config/stacks/fileManager.ts +++ b/config/stacks/fileManager.ts @@ -1,4 +1,3 @@ -import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { FilemanagerConfig } from '../../lib/workload/stateless/stacks/filemanager/deploy/stack'; import { AppStage, @@ -7,22 +6,15 @@ import { dbClusterEndpointHostParameterName, eventSourceQueueName, vpcProps, - cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName, - cognitoUserPoolIdParameterName, oncoanalyserBucket, icav2PipelineCacheBucket, fileManagerIngestRoleName, + logsApiGatewayConfig, + cognitoApiGatewayConfig, corsAllowOrigins, } from '../constants'; -import { RemovalPolicy } from 'aws-cdk-lib'; export const getFileManagerStackProps = (stage: AppStage): FilemanagerConfig => { - const logsConfig = { - retention: stage === AppStage.PROD ? RetentionDays.TWO_YEARS : RetentionDays.TWO_WEEKS, - removalPolicy: stage === AppStage.PROD ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY, - }; - return { securityGroupName: computeSecurityGroupName, vpcProps, @@ -30,13 +22,15 @@ export const getFileManagerStackProps = (stage: AppStage): FilemanagerConfig => databaseClusterEndpointHostParameter: dbClusterEndpointHostParameterName, port: databasePort, migrateDatabase: true, - cognitoPortalAppClientIdParameterName: cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName: cognitoStatusPageAppClientIdParameterName, - cognitoUserPoolIdParameterName: cognitoUserPoolIdParameterName, - apiGwLogsConfig: logsConfig, inventorySourceBuckets: ['filemanager-inventory-test'], eventSourceBuckets: [oncoanalyserBucket[stage], icav2PipelineCacheBucket[stage]], fileManagerIngestRoleName: fileManagerIngestRoleName, - corsAllowOrigins, + apiGatewayCognitoProps: { + ...cognitoApiGatewayConfig, + corsAllowOrigins: corsAllowOrigins[stage], + apiGwLogsConfig: logsApiGatewayConfig[stage], + apiName: 'FileManager', + customDomainNamePrefix: 'file', + }, }; }; diff --git a/config/stacks/metadataManager.ts b/config/stacks/metadataManager.ts index 6d7f0b63e..babfe63b8 100644 --- a/config/stacks/metadataManager.ts +++ b/config/stacks/metadataManager.ts @@ -1,27 +1,26 @@ import { AppStage, - cognitoApiGatewayProps, + cognitoApiGatewayConfig, computeSecurityGroupName, corsAllowOrigins, + logsApiGatewayConfig, vpcProps, } from '../constants'; import { MetadataManagerStackProps } from '../../lib/workload/stateless/stacks/metadata-manager/deploy/stack'; -import { RemovalPolicy } from 'aws-cdk-lib'; -import { RetentionDays } from 'aws-cdk-lib/aws-logs'; export const getMetadataManagerStackProps = (stage: AppStage): MetadataManagerStackProps => { - const logsConfig = { - retention: stage === AppStage.PROD ? RetentionDays.TWO_YEARS : RetentionDays.TWO_WEEKS, - removalPolicy: stage === AppStage.PROD ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY, - }; - const isDailySync = stage == AppStage.PROD ? true : false; return { vpcProps, isDailySync: isDailySync, lambdaSecurityGroupName: computeSecurityGroupName, - apiGatewayCognitoProps: { ...cognitoApiGatewayProps, apiGwLogsConfig: logsConfig }, - corsAllowOrigins, + apiGatewayCognitoProps: { + ...cognitoApiGatewayConfig, + corsAllowOrigins: corsAllowOrigins[stage], + apiGwLogsConfig: logsApiGatewayConfig[stage], + apiName: 'MetadataManager', + customDomainNamePrefix: 'metadata', + }, }; }; diff --git a/config/stacks/sequenceRunManager.ts b/config/stacks/sequenceRunManager.ts index 32592e562..470ae777b 100644 --- a/config/stacks/sequenceRunManager.ts +++ b/config/stacks/sequenceRunManager.ts @@ -1,31 +1,25 @@ import { AppStage, - cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName, - cognitoUserPoolIdParameterName, + cognitoApiGatewayConfig, computeSecurityGroupName, corsAllowOrigins, eventBusName, + logsApiGatewayConfig, vpcProps, } from '../constants'; import { SequenceRunManagerStackProps } from '../../lib/workload/stateless/stacks/sequence-run-manager/deploy/stack'; -import { RetentionDays } from 'aws-cdk-lib/aws-logs'; -import { RemovalPolicy } from 'aws-cdk-lib'; export const getSequenceRunManagerStackProps = (stage: AppStage): SequenceRunManagerStackProps => { - const logsConfig = { - retention: stage === AppStage.PROD ? RetentionDays.TWO_YEARS : RetentionDays.TWO_WEEKS, - removalPolicy: stage === AppStage.PROD ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY, - }; - return { vpcProps, lambdaSecurityGroupName: computeSecurityGroupName, mainBusName: eventBusName, - cognitoUserPoolIdParameterName: cognitoUserPoolIdParameterName, - cognitoPortalAppClientIdParameterName: cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName: cognitoStatusPageAppClientIdParameterName, - apiGwLogsConfig: logsConfig, - corsAllowOrigins, + apiGatewayCognitoProps: { + ...cognitoApiGatewayConfig, + corsAllowOrigins: corsAllowOrigins[stage], + apiGwLogsConfig: logsApiGatewayConfig[stage], + apiName: 'SequenceRunManager', + customDomainNamePrefix: 'sequence', + }, }; }; diff --git a/config/stacks/workflowRunManager.ts b/config/stacks/workflowRunManager.ts index ec07c368d..10773de59 100644 --- a/config/stacks/workflowRunManager.ts +++ b/config/stacks/workflowRunManager.ts @@ -1,31 +1,25 @@ -import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { WorkflowManagerStackProps } from '../../lib/workload/stateless/stacks/workflow-manager/deploy/stack'; import { vpcProps, computeSecurityGroupName, eventBusName, - cognitoUserPoolIdParameterName, - cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName, AppStage, + cognitoApiGatewayConfig, + logsApiGatewayConfig, corsAllowOrigins, } from '../constants'; -import { RemovalPolicy } from 'aws-cdk-lib'; export const getWorkflowManagerStackProps = (stage: AppStage): WorkflowManagerStackProps => { - const logsConfig = { - retention: stage === AppStage.PROD ? RetentionDays.TWO_YEARS : RetentionDays.TWO_WEEKS, - removalPolicy: stage === AppStage.PROD ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY, - }; - return { vpcProps, lambdaSecurityGroupName: computeSecurityGroupName, mainBusName: eventBusName, - cognitoUserPoolIdParameterName: cognitoUserPoolIdParameterName, - cognitoPortalAppClientIdParameterName: cognitoPortalAppClientIdParameterName, - cognitoStatusPageAppClientIdParameterName: cognitoStatusPageAppClientIdParameterName, - apiGwLogsConfig: logsConfig, - corsAllowOrigins, + apiGatewayCognitoProps: { + ...cognitoApiGatewayConfig, + corsAllowOrigins: corsAllowOrigins[stage], + apiGwLogsConfig: logsApiGatewayConfig[stage], + apiName: 'WorkflowManager', + customDomainNamePrefix: 'workflow', + }, }; }; diff --git a/docs/developer/MICROSERVICE.md b/docs/developer/MICROSERVICE.md index cd96e4599..a3fb308f2 100644 --- a/docs/developer/MICROSERVICE.md +++ b/docs/developer/MICROSERVICE.md @@ -17,6 +17,16 @@ Either tasks _(developing an app and/or cdk deployment constructs)_; we promote _Mac user: Option + M for the ยต symbol_ +### Using API as backend + +When integrating the microservice with a client, you might create a new Cognito app client ID. If this is the case, you +will need to add the new client ID to the AWS API Gateway setup to ensure the token generated by that Cognito app is +valid for use with the microservice API Gateway. Store this Cognito app ID in an SSM Parameter and pass the SSM +Parameter name in the `cognitoApiGatewayConfig` constant file (`./config/constants.ts`). Additionally, you may need to set +the appropriate CORS origin in the `corsAllowOrigins` constant file to prevent any CORS errors in your client. + +Reference on creating new Cognito App: + ### Native Bootstrap You may also just simply use "native toolchain bootstrap" method. This could be the typical "getting started" of respective tool or framework. Some examples as follows. diff --git a/lib/workload/components/api-gateway/index.ts b/lib/workload/components/api-gateway/index.ts index 2c3c6f3a7..0744b5220 100644 --- a/lib/workload/components/api-gateway/index.ts +++ b/lib/workload/components/api-gateway/index.ts @@ -21,15 +21,28 @@ export interface ApiGwLogsConfig { } export interface ApiGatewayConstructProps { + /** + * The AWS region. + */ region: string; - apiName: string | undefined; - cognitoUserPoolIdParameterName: string; - cognitoPortalAppClientIdParameterName: string; - cognitoStatusPageAppClientIdParameterName: string; + /** + * The name of the API. + */ + apiName: string; /** * The prefix for the custom domain name */ customDomainNamePrefix: string; + /** + *The cognito user pool id parameter name. + */ + cognitoUserPoolIdParameterName: string; + /** + * The parameter name for the cognito client id in array. + * In order API Gateway to validate the JWT token, it needs to know the client id which usually + * stored in SSM Parameter. This will accept multiple parameter name in an array. + */ + cognitoClientIdParameterNameArray: string[]; /** * The configuration for aws cloudwatch logs */ @@ -37,7 +50,7 @@ export interface ApiGatewayConstructProps { /** * Allowed CORS origins. */ - corsAllowOrigins?: string[]; + corsAllowOrigins: string[]; } export class ApiGatewayConstruct extends Construct { @@ -64,7 +77,15 @@ export class ApiGatewayConstruct extends Construct { this._httpApi = new HttpApi(this, 'HttpApi', { apiName: 'OrcaBusAPI-' + props.apiName, corsPreflight: { - allowHeaders: ['Authorization'], + allowHeaders: [ + 'content-type', + 'content-disposition', + 'authorization', + 'x-amz-date', + 'x-api-key', + 'x-amz-security-token', + 'x-amz-user-agent', + ], allowMethods: [ CorsHttpMethod.GET, CorsHttpMethod.HEAD, @@ -144,10 +165,6 @@ export class ApiGatewayConstruct extends Construct { * FIXME One fine day in future when we have proper Cognito AAI setup. * For the moment, we leverage Portal and established Cognito infrastructure. * See https://github.com/umccr/orcabus/issues/102 - * - * UI clients: - * https://portal.[dev|stg|prod].umccr.org - * https://status.[dev|stg|prod].umccr.org */ const userPoolIdParam: IStringParameter = aws_ssm.StringParameter.fromStringParameterName( @@ -155,23 +172,21 @@ export class ApiGatewayConstruct extends Construct { 'CognitoUserPoolIdParameter', props.cognitoUserPoolIdParameterName ); - const portalClientIdParam: IStringParameter = aws_ssm.StringParameter.fromStringParameterName( - this, - 'CognitoPortalClientIdParameter', - props.cognitoPortalAppClientIdParameterName + + const clientIdParamsArray: IStringParameter[] = props.cognitoClientIdParameterNameArray.map( + (name) => + aws_ssm.StringParameter.fromStringParameterName( + this, + `CognitoClientId${name}Parameter`, + name + ) ); - const statusPageClientIdParam: IStringParameter = - aws_ssm.StringParameter.fromStringParameterName( - this, - 'CognitoStatusPageClientIdParameter', - props.cognitoStatusPageAppClientIdParameterName - ); const issuer = 'https://cognito-idp.' + props.region + '.amazonaws.com/' + userPoolIdParam.stringValue; return new HttpJwtAuthorizer('PortalAuthorizer', issuer, { - jwtAudience: [portalClientIdParam.stringValue, statusPageClientIdParam.stringValue], + jwtAudience: clientIdParamsArray.map((param) => param.stringValue), }); } diff --git a/lib/workload/stateless/stacks/filemanager/deploy/stack.ts b/lib/workload/stateless/stacks/filemanager/deploy/stack.ts index 829d06b10..efa8d7332 100644 --- a/lib/workload/stateless/stacks/filemanager/deploy/stack.ts +++ b/lib/workload/stateless/stacks/filemanager/deploy/stack.ts @@ -7,7 +7,7 @@ import { Vpc, SecurityGroup, VpcLookupOptions, IVpc, ISecurityGroup } from 'aws- import { Arn, Stack, StackProps } from 'aws-cdk-lib'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; import { ProviderFunction } from '../../../../components/provider-function'; -import { ApiGatewayConstruct, ApiGwLogsConfig } from '../../../../components/api-gateway'; +import { ApiGatewayConstruct, ApiGatewayConstructProps } from '../../../../components/api-gateway'; import { IQueue, Queue } from 'aws-cdk-lib/aws-sqs'; import { HttpMethod, HttpRoute, HttpRouteKey } from 'aws-cdk-lib/aws-apigatewayv2'; import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations'; @@ -27,12 +27,8 @@ export type FilemanagerConfig = Omit & vpcProps: VpcLookupOptions; migrateDatabase?: boolean; securityGroupName: string; - cognitoUserPoolIdParameterName: string; - cognitoPortalAppClientIdParameterName: string; - cognitoStatusPageAppClientIdParameterName: string; - apiGwLogsConfig: ApiGwLogsConfig; fileManagerIngestRoleName: string; - corsAllowOrigins?: string[]; + apiGatewayCognitoProps: ApiGatewayConstructProps; }; /** @@ -143,21 +139,27 @@ export class Filemanager extends Stack { ...props, }); - const apiGateway = new ApiGatewayConstruct(this, 'ApiGateway', { - region: this.region, - apiName: 'FileManager', - customDomainNamePrefix: 'file', - ...props, - }); - + const apiGateway = new ApiGatewayConstruct(this, 'ApiGateway', props.apiGatewayCognitoProps); const httpApi = apiGateway.httpApi; const apiIntegration = new HttpLambdaIntegration('ApiIntegration', apiLambda.function); - new HttpRoute(this, 'HttpRoute', { + new HttpRoute(this, 'GetHttpRoute', { + httpApi: httpApi, + integration: apiIntegration, + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.GET), + }); + + new HttpRoute(this, 'PatchHttpRoute', { + httpApi: httpApi, + integration: apiIntegration, + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.PATCH), + }); + + new HttpRoute(this, 'PostHttpRoute', { httpApi: httpApi, integration: apiIntegration, - routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.ANY), + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.POST), }); return apiGateway.domainName; diff --git a/lib/workload/stateless/stacks/metadata-manager/deploy/construct/lambda-api/index.ts b/lib/workload/stateless/stacks/metadata-manager/deploy/construct/lambda-api/index.ts index e4ea4eaef..ef576536c 100644 --- a/lib/workload/stateless/stacks/metadata-manager/deploy/construct/lambda-api/index.ts +++ b/lib/workload/stateless/stacks/metadata-manager/deploy/construct/lambda-api/index.ts @@ -22,10 +22,6 @@ type LambdaProps = { * The props for api-gateway */ apiGatewayConstructProps: ApiGatewayConstructProps; - /** - * Allowed CORS origins. - */ - corsAllowOrigins?: string[]; }; export class LambdaAPIConstruct extends Construct { @@ -54,7 +50,7 @@ export class LambdaAPIConstruct extends Construct { new HttpRoute(this, 'ApiLambdaHttpRoute', { httpApi: apiGW.httpApi, integration: apiIntegration, - routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.ANY), + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.GET), }); } } diff --git a/lib/workload/stateless/stacks/metadata-manager/deploy/stack.ts b/lib/workload/stateless/stacks/metadata-manager/deploy/stack.ts index 49758fdfb..7817f5bf9 100644 --- a/lib/workload/stateless/stacks/metadata-manager/deploy/stack.ts +++ b/lib/workload/stateless/stacks/metadata-manager/deploy/stack.ts @@ -25,20 +25,10 @@ export type MetadataManagerStackProps = { * A boolean to tell whether the sync lambda should run daily */ isDailySync: boolean; - /** - * Allowed CORS origins. - */ - corsAllowOrigins?: string[]; /** * API Gateway props */ - apiGatewayCognitoProps: Pick< - ApiGatewayConstructProps, - | 'cognitoUserPoolIdParameterName' - | 'cognitoPortalAppClientIdParameterName' - | 'cognitoStatusPageAppClientIdParameterName' - | 'apiGwLogsConfig' - >; + apiGatewayCognitoProps: ApiGatewayConstructProps; }; export class MetadataManagerStack extends Stack { @@ -97,13 +87,7 @@ export class MetadataManagerStack extends Stack { new LambdaAPIConstruct(this, 'APILambda', { basicLambdaConfig: basicLambdaConfig, dbConnectionSecret: dbSecret, - apiGatewayConstructProps: { - region: this.region, - apiName: 'MetadataManager', - customDomainNamePrefix: 'metadata', - ...props.apiGatewayCognitoProps, - }, - corsAllowOrigins: props.corsAllowOrigins, + apiGatewayConstructProps: props.apiGatewayCognitoProps, }); // (2) diff --git a/lib/workload/stateless/stacks/sequence-run-manager/deploy/stack.ts b/lib/workload/stateless/stacks/sequence-run-manager/deploy/stack.ts index 77ca08376..27f5b0381 100644 --- a/lib/workload/stateless/stacks/sequence-run-manager/deploy/stack.ts +++ b/lib/workload/stateless/stacks/sequence-run-manager/deploy/stack.ts @@ -8,7 +8,7 @@ import { PythonFunction, PythonLayerVersion } from '@aws-cdk/aws-lambda-python-a import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations'; import { HttpMethod, HttpRoute, HttpRouteKey } from 'aws-cdk-lib/aws-apigatewayv2'; import { ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { ApiGatewayConstruct, ApiGwLogsConfig } from '../../../../components/api-gateway'; +import { ApiGatewayConstruct, ApiGatewayConstructProps } from '../../../../components/api-gateway'; import { Architecture } from 'aws-cdk-lib/aws-lambda'; import { PostgresManagerStack } from '../../../../stateful/stacks/postgres-manager/deploy/stack'; @@ -16,11 +16,7 @@ export interface SequenceRunManagerStackProps { lambdaSecurityGroupName: string; vpcProps: VpcLookupOptions; mainBusName: string; - cognitoUserPoolIdParameterName: string; - cognitoPortalAppClientIdParameterName: string; - cognitoStatusPageAppClientIdParameterName: string; - apiGwLogsConfig: ApiGwLogsConfig; - corsAllowOrigins?: string[]; + apiGatewayCognitoProps: ApiGatewayConstructProps; } export class SequenceRunManagerStack extends Stack { @@ -116,20 +112,15 @@ export class SequenceRunManagerStack extends Stack { timeout: Duration.seconds(28), }); - const srmApi = new ApiGatewayConstruct(this, 'ApiGateway', { - region: this.region, - apiName: 'SequenceRunManager', - customDomainNamePrefix: 'sequence', - ...props, - }); + const srmApi = new ApiGatewayConstruct(this, 'ApiGateway', props.apiGatewayCognitoProps); const httpApi = srmApi.httpApi; const apiIntegration = new HttpLambdaIntegration('ApiIntegration', apiFn); - new HttpRoute(this, 'HttpRoute', { + new HttpRoute(this, 'GetHttpRoute', { httpApi: httpApi, integration: apiIntegration, - routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.ANY), + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.GET), }); } diff --git a/lib/workload/stateless/stacks/workflow-manager/deploy/stack.ts b/lib/workload/stateless/stacks/workflow-manager/deploy/stack.ts index d18ae4fc5..d7e1c187a 100644 --- a/lib/workload/stateless/stacks/workflow-manager/deploy/stack.ts +++ b/lib/workload/stateless/stacks/workflow-manager/deploy/stack.ts @@ -16,17 +16,13 @@ import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations import { HttpMethod, HttpRoute, HttpRouteKey } from 'aws-cdk-lib/aws-apigatewayv2'; import { PostgresManagerStack } from '../../../../stateful/stacks/postgres-manager/deploy/stack'; import { ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { ApiGatewayConstruct, ApiGwLogsConfig } from '../../../../components/api-gateway'; +import { ApiGatewayConstruct, ApiGatewayConstructProps } from '../../../../components/api-gateway'; export interface WorkflowManagerStackProps extends StackProps { lambdaSecurityGroupName: string; vpcProps: VpcLookupOptions; mainBusName: string; - cognitoUserPoolIdParameterName: string; - cognitoPortalAppClientIdParameterName: string; - cognitoStatusPageAppClientIdParameterName: string; - apiGwLogsConfig: ApiGwLogsConfig; - corsAllowOrigins?: string[]; + apiGatewayCognitoProps: ApiGatewayConstructProps; } export class WorkflowManagerStack extends Stack { @@ -121,20 +117,15 @@ export class WorkflowManagerStack extends Stack { timeout: Duration.seconds(28), }); - const wfmApi = new ApiGatewayConstruct(this, 'ApiGateway', { - region: this.region, - apiName: 'WorkflowManager', - customDomainNamePrefix: 'workflow', - ...props, - }); + const wfmApi = new ApiGatewayConstruct(this, 'ApiGateway', props.apiGatewayCognitoProps); const httpApi = wfmApi.httpApi; const apiIntegration = new HttpLambdaIntegration('ApiIntegration', apiFn); - new HttpRoute(this, 'HttpRoute', { + new HttpRoute(this, 'GetHttpRoute', { httpApi: httpApi, integration: apiIntegration, - routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.ANY), + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.GET), }); } diff --git a/skel/django-api/deploy/stack.ts b/skel/django-api/deploy/stack.ts index 1cce264a7..e44ecb36f 100644 --- a/skel/django-api/deploy/stack.ts +++ b/skel/django-api/deploy/stack.ts @@ -11,17 +11,13 @@ import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations import { HttpMethod, HttpRoute, HttpRouteKey } from 'aws-cdk-lib/aws-apigatewayv2'; import { PostgresManagerStack } from '../../../lib/workload/stateful/stacks/postgres-manager/deploy/stack'; import { ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { ApiGatewayConstruct, ApiGwLogsConfig } from '../../../lib/workload/components/api-gateway'; +import { ApiGatewayConstruct, ApiGatewayConstructProps } from '../../../lib/workload/components/api-gateway'; export interface ProjectNameStackProps { // FIXME change prop interface name lambdaSecurityGroupName: string; vpcProps: VpcLookupOptions; mainBusName: string; - cognitoUserPoolIdParameterName: string; - cognitoPortalAppClientIdParameterName: string; - cognitoStatusPageAppClientIdParameterName: string; - apiGwLogsConfig: ApiGwLogsConfig; - corsAllowOrigins?: string[]; + apiGatewayCognitoProps: ApiGatewayConstructProps; } export class ProjectNameStack extends Stack { // FIXME change construct name @@ -116,20 +112,15 @@ export class ProjectNameStack extends Stack { // FIXME change construct name timeout: Duration.seconds(28), }); - const srmApi = new ApiGatewayConstruct(this, 'ApiGateway', { - region: this.region, - apiName: 'SequenceRunManager', - customDomainNamePrefix: 'sequence', - ...props, - }); + const srmApi = new ApiGatewayConstruct(this, 'ApiGateway', props.apiGatewayCognitoProps); const httpApi = srmApi.httpApi; const apiIntegration = new HttpLambdaIntegration('ApiIntegration', apiFn); - new HttpRoute(this, 'HttpRoute', { + new HttpRoute(this, 'GetHttpRoute', { httpApi: httpApi, integration: apiIntegration, - routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.ANY), + routeKey: HttpRouteKey.with('/{proxy+}', HttpMethod.GET), }); }