Skip to content

Commit

Permalink
Address PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebearden committed Feb 2, 2023
1 parent e284d2f commit 7fa9ae9
Show file tree
Hide file tree
Showing 13 changed files with 455 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ new ApiGatewayToDynamoDB(this, "test-api-gateway-dynamodb-default", new ApiGatew
|apiGatewayProps?|[`api.RestApiProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApiProps.html)|Optional user-provided props to override the default props for the API Gateway.|
|allowCreateOperation?|`boolean`|Whether to deploy an API Gateway Method for POST HTTP operations on the DynamoDB table (i.e. dynamodb:PutItem).|
|createRequestTemplate?|`string`|API Gateway Request Template for the create method for the default `application/json` content-type. This property is required if the `allowCreateOperation` property is set to true.|
|additionalCreateRequestTemplates?|`{ [contentType: string]: string; }`|Optional Create Request Templates for content-types other than `application/json`. Use the `createRequestTemplate` property to set the request template for the `application/json` content-type.|
|createIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the create method, if the `allowCreateOperation` property is set to true.|
|additionalCreateRequestTemplates?|`{ [contentType: string]: string; }`|Optional Create Request Templates for content-types other than `application/json`. Use the `createRequestTemplate` property to set the request template for the `application/json` content-type. This property can only be specified if the `allowCreateOperation` property is set to true.|
|createIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the create method. This property can only be specified if the `allowCreateOperation` property is set to true.|
|allowReadOperation?|`boolean`|Whether to deploy an API Gateway Method for GET HTTP operations on DynamoDB table (i.e. dynamodb:Query).|
|readRequestTemplate?|`string`|API Gateway Request Template for the read method for the default `application/json` content-type, if the `allowReadOperation` property is set to true. The default template only supports a partition key and not partition + sort keys.|
|readRequestTemplate?|`string`|API Gateway Request Template for the read method for the default `application/json` content-type. The default template only supports a partition key and not partition + sort keys.|
|additionalReadRequestTemplates?|`{ [contentType: string]: string; }`|Optional Read Request Templates for content-types other than `application/json`. Use the `readRequestTemplate` property to set the request template for the `application/json` content-type.|
|readIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the read method, if the `allowReadOperation` property is set to true.|
|readIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the read method.|
|allowUpdateOperation?|`boolean`|Whether to deploy API Gateway Method for PUT HTTP operations on DynamoDB table (i.e. dynamodb:UpdateItem).|
|updateRequestTemplate?|`string`|API Gateway Request Template for the update method, required if the `allowUpdateOperation` property is set to true.|
|additionalUpdateRequestTemplates?|`{ [contentType: string]: string; }`|Optional Update Request Templates for content-types other than `application/json`. Use the `updateRequestTemplate` property to set the request template for the `application/json` content-type.|
|updateIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the update method, if the `allowUpdateOperation` property is set to true.|
|updateRequestTemplate?|`string`|API Gateway Request Template for the update method. This property is required if the `allowUpdateOperation` property is set to true.|
|additionalUpdateRequestTemplates?|`{ [contentType: string]: string; }`|Optional Update Request Templates for content-types other than `application/json`. Use the `updateRequestTemplate` property to set the request template for the `application/json` content-type. This property can only be specified if the `allowUpdateOperation` property is set to true.|
|updateIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the update method. This property can only be specified if the `allowUpdateOperation` property is set to true.|
|allowDeleteOperation?|`boolean`|Whether to deploy API Gateway Method for DELETE HTTP operations on DynamoDB table (i.e. dynamodb:DeleteItem).|
|deleteRequestTemplate?|`string`|API Gateway Request Template for the delete method for the default `application/json` content-type, if the `allowDeleteOperation` property is set to true.|
|additionalDeleteRequestTemplates?|`{ [contentType: string]: string; }`|Optional Delete request templates for content-types other than `application/json`. Use the `deleteRequestTemplate` property to set the request template for the `application/json` content-type.|
|deleteIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the delete method, if the `allowDeleteOperation` property is set to true.|
|deleteRequestTemplate?|`string`|API Gateway Request Template for the delete method for the default `application/json` content-type. |
|additionalDeleteRequestTemplates?|`{ [contentType: string]: string; }`|Optional Delete request templates for content-types other than `application/json`. Use the `deleteRequestTemplate` property to set the request template for the `application/json` content-type. This property can only be specified if the `allowDeleteOperation` property is set to true.|
|deleteIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the delete method. This property can only be specified if the `allowDeleteOperation` property is set to true.|
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroupProps.html)|User provided props to override the default props for for the CloudWatchLogs LogGroup.|

## Pattern Properties
Expand All @@ -93,6 +93,13 @@ new ApiGatewayToDynamoDB(this, "test-api-gateway-dynamodb-default", new ApiGatew
|apiGatewayCloudWatchRole?|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.Role.html)|Returns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.|
|apiGatewayLogGroup|[`logs.LogGroup`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|

# API Gateway Request/Response Template Properties Overview
There are sets of properties corresponding to the various API operations this construct supports (CREATE/READ/UPDATE/DELETE). Each API operation has a property to enable it, followed by a set of properties used to specify request templates and integration responses. Taking the **CREATE** operation as an example:
* The API method is enabled by setting the `allowCreateOperation` property to true.
* Once set, the request template for the `application/json` content-type can be set using the `createRequestTemplate` property.
* Additional request templates for content-types other than `application/json` can be specified in the `additionalCreateRequestTemplates` property.
* Non-default integration responses can be specified in the `createIntegrationResponses` property.

## Default settings

Out of the box implementation of the Construct without any override will set the following defaults:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ export interface ApiGatewayToDynamoDBProps {
/**
* Optional Create Request Templates for content-types other than `application/json`.
* Use the `createRequestTemplate` property to set the request template for the `application/json` content-type.
* This property can only be specified if the `allowCreateOperation` property is set to true.
*
* @default - None
*/
readonly additionalCreateRequestTemplates?: { [contentType: string]: string; };
/**
* Optional, custom API Gateway Integration Response for the create method, if the `allowCreateOperation` property is set to true.
* Optional, custom API Gateway Integration Response for the create method.
* This property can only be specified if the `allowCreateOperation` property is set to true.
*
* @default - [{statusCode:"200"},{statusCode:"500",responseTemplates:{"text/html":"Error"},selectionPattern:"500"}]
*/
Expand All @@ -76,8 +78,7 @@ export interface ApiGatewayToDynamoDBProps {
*/
readonly allowReadOperation?: boolean;
/**
* API Gateway Request Template for the read method for the default `application/json` content-type,
* if the `allowReadOperation` property is set to true.
* API Gateway Request Template for the read method for the default `application/json` content-type.
*
* The default template only supports a partition key and not partition + sort keys.
*
Expand All @@ -100,7 +101,7 @@ export interface ApiGatewayToDynamoDBProps {
*/
readonly additionalReadRequestTemplates?: { [contentType: string]: string; };
/**
* Optional, custom API Gateway Integration Response for the read method, if the `allowReadOperation` property is set to true.
* Optional, custom API Gateway Integration Response for the read method.
*
* @default - [{statusCode:"200"},{statusCode:"500",responseTemplates:{"text/html":"Error"},selectionPattern:"500"}]
*/
Expand All @@ -112,20 +113,23 @@ export interface ApiGatewayToDynamoDBProps {
*/
readonly allowUpdateOperation?: boolean;
/**
* API Gateway Request Template for the update method, required if the `allowUpdateOperation` property is set to true.
* API Gateway Request Template for the update method.
* This property is required if the `allowUpdateOperation` property is set to true.
*
* @default - None
*/
readonly updateRequestTemplate?: string;
/**
* Optional Update Request Templates for content-types other than `application/json`.
* Use the `updateRequestTemplate` property to set the request template for the `application/json` content-type.
* This property can only be specified if the `allowUpdateOperation` property is set to true.
*
* @default - None
*/
readonly additionalUpdateRequestTemplates?: { [contentType: string]: string; };
/**
* Optional, custom API Gateway Integration Response for the update method, if the `allowUpdateOperation` property is set to true.
* Optional, custom API Gateway Integration Response for the update method.
* This property can only be specified if the `allowUpdateOperation` property is set to true.
*
* @default - [{statusCode:"200"},{statusCode:"500",responseTemplates:{"text/html":"Error"},selectionPattern:"500"}]
*/
Expand All @@ -137,8 +141,8 @@ export interface ApiGatewayToDynamoDBProps {
*/
readonly allowDeleteOperation?: boolean;
/**
* API Gateway Request Template for the delete method for the default `application/json` content-type,
* if the `allowDeleteOperation` property is set to true.
* API Gateway Request Template for the delete method for the default `application/json` content-type.
* This property can only be specified if the `allowDeleteOperation` property is set to true.
*
* @default - `{ \
* "TableName": "DYNAMODB_TABLE_NAME", \
Expand All @@ -154,12 +158,14 @@ export interface ApiGatewayToDynamoDBProps {
/**
* Optional Delete request templates for content-types other than `application/json`.
* Use the `deleteRequestTemplate` property to set the request template for the `application/json` content-type.
* This property can only be specified if the `allowDeleteOperation` property is set to true.
*
* @default - None
*/
readonly additionalDeleteRequestTemplates?: { [contentType: string]: string; };
/**
* Optional, custom API Gateway Integration Response for the delete method, if the `allowDeleteOperation` property is set to true.
* Optional, custom API Gateway Integration Response for the delete method.
* This property can only be specified if the `allowDeleteOperation` property is set to true.
*
* @default - [{statusCode:"200"},{statusCode:"500",responseTemplates:{"text/html":"Error"},selectionPattern:"500"}]
*/
Expand Down Expand Up @@ -193,6 +199,27 @@ export class ApiGatewayToDynamoDB extends Construct {
super(scope, id);
defaults.CheckProps(props);

if ((props.createRequestTemplate || props.additionalCreateRequestTemplates || props.createIntegrationResponses)
&& props.allowCreateOperation !== true) {
throw new Error(`The 'allowCreateOperation' property must be set to true when setting any of the following: ` +
`'createRequestTemplate', 'additionalCreateRequestTemplates', 'createIntegrationResponses'`);
}
if ((props.readRequestTemplate || props.additionalReadRequestTemplates || props.readIntegrationResponses)
&& props.allowReadOperation === false) {
throw new Error(`The 'allowReadOperation' property must be set to true or undefined when setting any of the following: ` +
`'readRequestTemplate', 'additionalReadRequestTemplates', 'readIntegrationResponses'`);
}
if ((props.updateRequestTemplate || props.additionalUpdateRequestTemplates || props.updateIntegrationResponses)
&& props.allowUpdateOperation !== true) {
throw new Error(`The 'allowUpdateOperation' property must be set to true when setting any of the following: ` +
`'updateRequestTemplate', 'additionalUpdateRequestTemplates', 'updateIntegrationResponses'`);
}
if ((props.deleteRequestTemplate || props.additionalDeleteRequestTemplates || props.deleteIntegrationResponses)
&& props.allowDeleteOperation !== true) {
throw new Error(`The 'allowDeleteOperation' property must be set to true when setting any of the following: ` +
`'deleteRequestTemplate', 'additionalDeleteRequestTemplates', 'deleteIntegrationResponses'`);
}

// Set the default props for DynamoDB table
const dynamoTableProps: dynamodb.TableProps = defaults.consolidateProps(defaults.DefaultTableProps, props.dynamoTableProps);
let partitionKeyName = dynamoTableProps.partitionKey.name;
Expand Down
Loading

0 comments on commit 7fa9ae9

Please sign in to comment.