diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md index be5017cab..c28786e40 100755 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md @@ -78,7 +78,7 @@ Out of the box implementation of the Construct without any override will set the ### Amazon API Gateway -* Deploy an edge-optimized API endpoint +* Deploy an edge-optimized API Endpoint * Creates API Resources with `POST` Method to publish messages to IoT Topics * Creates API Resources with `POST` Method to publish messages to ThingShadow & NamedShadows * Enable CloudWatch logging for API Gateway diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts index 736e25af3..7104419ad 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts @@ -153,9 +153,7 @@ test('override api gateway properties with existingLambdaObj', () => { new CloudFrontToApiGatewayToLambda(stack, 'test-cloudfront-apigateway-lambda', { existingLambdaObj: fn, apiGatewayProps: { - options: { - description: "Override description" - } + description: "Override description" } }); @@ -184,9 +182,7 @@ test('override api gateway properties without existingLambdaObj', () => { endpointConfiguration: { types: [api.EndpointType.PRIVATE], }, - options: { - description: "Override description" - } + description: "Override description" } }); diff --git a/source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts index afed0155e..b4dc1d9c6 100644 --- a/source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts @@ -101,21 +101,23 @@ function configureLambdaRestApi(scope: Construct, defaultApiGatewayProps: api.La cwRole = configureCloudwatchRoleForApi(scope, _api); } - let usagePlanProps: api.UsagePlanProps = { + // Configure Usage Plan + const usagePlanProps: api.UsagePlanProps = { apiStages: [{ api: _api, stage: _api.deploymentStage }] }; - // If requireApiKey param is set to true, create a api key & associate to Usage Plan + + const plan = _api.addUsagePlan('UsagePlan', usagePlanProps); + + // If requireApiKey param is set to true, create a api key & associate to Usage Plan if (apiGatewayProps?.defaultMethodOptions?.apiKeyRequired === true) { - const extraParams = { apiKey: _api.addApiKey('ApiKey')}; - usagePlanProps = Object.assign(usagePlanProps, extraParams); + // Configure Usage Plan with API Key + const key = _api.addApiKey('ApiKey'); + plan.addApiKey(key); } - // Configure Usage Plan - _api.addUsagePlan('UsagePlan', usagePlanProps); - // Return the API and CW Role return [_api, cwRole]; } @@ -152,22 +154,23 @@ function configureRestApi(scope: Construct, defaultApiGatewayProps: api.RestApiP cwRole = configureCloudwatchRoleForApi(scope, _api); } - let usagePlanProps: api.UsagePlanProps = { + // Configure Usage Plan + const usagePlanProps: api.UsagePlanProps = { apiStages: [{ api: _api, stage: _api.deploymentStage }] }; + const plan = _api.addUsagePlan('UsagePlan', usagePlanProps); + // If requireApiKey param is set to true, create a api key & associate to Usage Plan if (apiGatewayProps?.defaultMethodOptions?.apiKeyRequired === true) { - const extraParams = { apiKey: _api.addApiKey('ApiKey')}; - usagePlanProps = Object.assign(usagePlanProps, extraParams); + // Configure Usage Plan with API Key + const key = _api.addApiKey('ApiKey'); + plan.addApiKey(key); } - // Configure Usage Plan - _api.addUsagePlan('UsagePlan', usagePlanProps); - // Return the API and CW Role return [_api, cwRole]; }