diff --git a/packages/aws-cdk-lib/aws-apigateway/lib/integration.ts b/packages/aws-cdk-lib/aws-apigateway/lib/integration.ts index d9a371b12bc7c..1415128cf5319 100644 --- a/packages/aws-cdk-lib/aws-apigateway/lib/integration.ts +++ b/packages/aws-cdk-lib/aws-apigateway/lib/integration.ts @@ -167,6 +167,8 @@ export interface IntegrationConfig { /** * The integration's HTTP method type. + * Required unless you use a MOCK integration. + * * @default - no integration method specified. */ readonly integrationHttpMethod?: string; @@ -205,6 +207,10 @@ export class Integration { if (options.timeout && !options.timeout.isUnresolved() && (options.timeout.toMilliseconds() < 50 || options.timeout.toMilliseconds() > 29000)) { throw new Error('Integration timeout must be between 50 milliseconds and 29 seconds.'); } + + if (props.type !== IntegrationType.MOCK && !props.integrationHttpMethod) { + throw new Error('integrationHttpMethod is required for non-mock integration types.'); + } } /** diff --git a/packages/aws-cdk-lib/aws-apigateway/test/integration.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/integration.test.ts index c48743f8c2a98..f093bdeb69337 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/integration.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/integration.test.ts @@ -14,6 +14,7 @@ describe('integration', () => { // THEN expect(() => new apigw.Integration({ type: apigw.IntegrationType.AWS_PROXY, + integrationHttpMethod: 'ANY', options: { credentialsPassthrough: true, credentialsRole: role, @@ -229,4 +230,21 @@ describe('integration', () => { }); + test('validates integrationHttpMethod is required for non-MOCK integration types', () => { + expect(() => new apigw.Integration({ + type: apigw.IntegrationType.HTTP_PROXY, + options: { + timeout: cdk.Duration.seconds(15), + }, + })).toThrow(/integrationHttpMethod is required for non-mock integration types/); + }); + + test('integrationHttpMethod can be omitted for MOCK integration type', () => { + expect(() => new apigw.Integration({ + type: apigw.IntegrationType.MOCK, + options: { + timeout: cdk.Duration.seconds(15), + }, + })).not.toThrow(); + }); }); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts index f69fdac969d74..fbf92277a920d 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts @@ -140,7 +140,11 @@ describe('method', () => { test('use default integration from api', () => { // GIVEN const stack = new cdk.Stack(); - const defaultIntegration = new apigw.Integration({ type: apigw.IntegrationType.HTTP_PROXY, uri: 'https://amazon.com' }); + const defaultIntegration = new apigw.Integration({ + type: apigw.IntegrationType.HTTP_PROXY, + integrationHttpMethod: 'POST', + uri: 'https://amazon.com', + }); const api = new apigw.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: false, @@ -309,6 +313,7 @@ describe('method', () => { // WHEN api.root.addMethod('GET', new apigw.Integration({ type: apigw.IntegrationType.AWS_PROXY, + integrationHttpMethod: 'GET', options: { credentialsRole: role, }, @@ -331,6 +336,7 @@ describe('method', () => { // WHEN api.root.addMethod('GET', new apigw.Integration({ type: apigw.IntegrationType.AWS_PROXY, + integrationHttpMethod: 'GET', options: { credentialsPassthrough: true, },