Skip to content

Commit

Permalink
Update to version v1.53.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hnishar committed Jul 27, 2020
1 parent fa0e2fa commit ccf819c
Show file tree
Hide file tree
Showing 129 changed files with 5,827 additions and 613 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.53.0] - 2020-07-27

### Added
- aws-lambda-sqs-lambda pattern added

### Changed
- Upgraded all patterns to CDK v1.53.0
- Expose all cdk objects created by the construct as pattern properties

## [1.52.0] - 2020-07-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion source/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"./patterns/@aws-solutions-constructs/*"
],
"rejectCycles": "true",
"version": "1.52.0"
"version": "1.53.0"
}
2 changes: 1 addition & 1 deletion source/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-solutions-constructs",
"version": "1.52.0",
"version": "1.53.0",
"description": "AWS Solutions Constructs Library",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ _Parameters_
|apiGateway|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApi.html)|Returns an instance of the api.RestApi created by the construct.|
|apiGatewayRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html)|Returns an instance of the iam.Role created by the construct for API Gateway.|
|dynamoTable|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Returns an instance of dynamodb.Table created by the construct.|
|apiGatewayCloudWatchRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_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/latest/docs/@aws-cdk_aws-logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|

## Default settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as defaults from '@aws-solutions-constructs/core';
import { Construct } from '@aws-cdk/core';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import { overrideProps } from '@aws-solutions-constructs/core';
import { LogGroup } from '@aws-cdk/aws-logs';

/**
* @summary The properties for the ApiGatewayToDynamoDB class.
Expand All @@ -33,7 +34,7 @@ export interface ApiGatewayToDynamoDBProps {
*
* @default - Default properties are used.
*/
readonly apiGatewayProps?: api.RestApiProps | any,
readonly apiGatewayProps?: api.RestApiProps,

/**
* Whether to deploy API Gateway Method for Create operation on DynamoDB table.
Expand Down Expand Up @@ -85,7 +86,8 @@ export class ApiGatewayToDynamoDB extends Construct {
public readonly dynamoTable: dynamodb.Table;
public readonly apiGatewayRole: iam.Role;
public readonly apiGateway: api.RestApi;

public readonly apiGatewayCloudWatchRole: iam.Role;
public readonly apiGatewayLogGroup: LogGroup;
/**
* @summary Constructs a new instance of the ApiGatewayToDynamoDB class.
* @param {cdk.App} scope - represents the scope for all the resources.
Expand All @@ -109,7 +111,7 @@ export class ApiGatewayToDynamoDB extends Construct {
}

// Setup the API Gateway
this.apiGateway = defaults.GlobalRestApi(this);
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this, props.apiGatewayProps);

// Setup the API Gateway role
this.apiGatewayRole = new iam.Role(this, 'api-gateway-role', {
Expand All @@ -123,30 +125,30 @@ export class ApiGatewayToDynamoDB extends Construct {
// Create
if (props.allowCreateOperation && props.allowCreateOperation === true && props.createRequestTemplate) {
const createRequestTemplate = props.createRequestTemplate.replace("${Table}", this.dynamoTable.tableName);
this.addActiontoPlicy("dynamodb:PutItem");
this.addActionToPolicy("dynamodb:PutItem");
this.addMethod(this.apiGateway.root, createRequestTemplate, "PutItem", "POST");
}
// Read
if (!props.allowReadOperation || props.allowReadOperation === true) {
const getRequestTemplate = "{\r\n\"TableName\": \"" + this.dynamoTable.tableName + "\",\r\n \"KeyConditionExpression\": \"" + partitionKeyName + " = :v1\",\r\n \"ExpressionAttributeValues\": {\r\n \":v1\": {\r\n \"S\": \"$input.params('" + partitionKeyName + "')\"\r\n }\r\n }\r\n}";
this.addActiontoPlicy("dynamodb:Query");
this.addActionToPolicy("dynamodb:Query");
this.addMethod(apiGatewayResource, getRequestTemplate, "Query", "GET");
}
// Update
if (props.allowUpdateOperation && props.allowUpdateOperation === true && props.updateRequestTemplate) {
const updateRequestTemplate = props.updateRequestTemplate.replace("${Table}", this.dynamoTable.tableName);
this.addActiontoPlicy("dynamodb:UpdateItem");
this.addActionToPolicy("dynamodb:UpdateItem");
this.addMethod(apiGatewayResource, updateRequestTemplate, "UpdateItem", "PUT");
}
// Delete
if (props.allowDeleteOperation && props.allowDeleteOperation === true) {
const deleteRequestTemplate = "{\r\n \"TableName\": \"" + this.dynamoTable.tableName + "\",\r\n \"Key\": {\r\n \"" + partitionKeyName + "\": {\r\n \"S\": \"$input.params('" + partitionKeyName + "')\"\r\n }\r\n },\r\n \"ConditionExpression\": \"attribute_not_exists(Replies)\",\r\n \"ReturnValues\": \"ALL_OLD\"\r\n}";
this.addActiontoPlicy("dynamodb:DeleteItem");
this.addActionToPolicy("dynamodb:DeleteItem");
this.addMethod(apiGatewayResource, deleteRequestTemplate, "DeleteItem", "DELETE");
}
}

private addActiontoPlicy(action: string) {
private addActionToPolicy(action: string) {
this.apiGatewayRole.addToPolicy(new iam.PolicyStatement({
resources: [
this.dynamoTable.tableArn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-solutions-constructs/aws-apigateway-dynamodb",
"version": "1.52.0",
"version": "1.53.0",
"description": "CDK Constructs for AWS API Gateway and Amazon DynamoDB integration.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -53,15 +53,16 @@
}
},
"dependencies": {
"@aws-cdk/core": "~1.52.0",
"@aws-cdk/aws-apigateway": "~1.52.0",
"@aws-cdk/aws-iam": "~1.52.0",
"@aws-cdk/aws-dynamodb": "~1.52.0",
"@aws-solutions-constructs/core": "~1.52.0",
"@aws-cdk/core": "~1.53.0",
"@aws-cdk/aws-apigateway": "~1.53.0",
"@aws-cdk/aws-iam": "~1.53.0",
"@aws-cdk/aws-dynamodb": "~1.53.0",
"@aws-cdk/aws-logs": "~1.53.0",
"@aws-solutions-constructs/core": "~1.53.0",
"constructs": "^3.0.2"
},
"devDependencies": {
"@aws-cdk/assert": "~1.52.0",
"@aws-cdk/assert": "~1.53.0",
"@types/jest": "^24.0.23",
"@types/node": "^10.3.0"
},
Expand All @@ -71,11 +72,12 @@
]
},
"peerDependencies": {
"@aws-cdk/core": "~1.52.0",
"@aws-cdk/aws-apigateway": "~1.52.0",
"@aws-cdk/aws-iam": "~1.52.0",
"@aws-cdk/aws-dynamodb": "~1.52.0",
"@aws-solutions-constructs/core": "~1.52.0",
"constructs": "^3.0.2"
"@aws-cdk/core": "~1.53.0",
"@aws-cdk/aws-apigateway": "~1.53.0",
"@aws-cdk/aws-iam": "~1.53.0",
"@aws-cdk/aws-dynamodb": "~1.53.0",
"@aws-solutions-constructs/core": "~1.53.0",
"constructs": "^3.0.2",
"@aws-cdk/aws-logs": "~1.53.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ test('check properties', () => {
expect(construct.dynamoTable !== null);
expect(construct.apiGateway !== null);
expect(construct.apiGatewayRole !== null);
expect(construct.apiGatewayCloudWatchRole !== null);
expect(construct.apiGatewayLogGroup !== null);
});

test('check allow CRUD operations', () => {
Expand Down Expand Up @@ -191,3 +193,18 @@ test('check using custom partition key for dynamodb', () => {
});

});

test('override apiGatewayProps for api gateway', () => {
const stack = new Stack();
const apiGatewayToDynamoDBProps: ApiGatewayToDynamoDBProps = {
apiGatewayProps: {
description: 'This is a sample description for api gateway'
}
};
new ApiGatewayToDynamoDB(stack, 'test-api-gateway-dynamodb', apiGatewayToDynamoDBProps);

expect(stack).toHaveResource("AWS::ApiGateway::RestApi", {
Description: "This is a sample description for api gateway"
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ _Parameters_
|:-------------|:----------------|-----------------|
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of the Lambda function created by the pattern.|
|restApi|[`api.LambdaRestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.LambdaRestApi.html)|Returns an instance of the API Gateway REST API created by the pattern.|
|apiGatewayCloudWatchRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_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/latest/docs/@aws-cdk_aws-logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|

## Default settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// Imports
import * as api from '@aws-cdk/aws-apigateway';
import * as lambda from '@aws-cdk/aws-lambda';
import * as iam from '@aws-cdk/aws-iam';
import { LogGroup } from '@aws-cdk/aws-logs';
import * as defaults from '@aws-solutions-constructs/core';
import { Construct } from '@aws-cdk/core';

Expand All @@ -32,7 +34,7 @@ export interface ApiGatewayToLambdaProps {
*
* @default - Default props are used.
*/
readonly lambdaFunctionProps?: lambda.FunctionProps | any
readonly lambdaFunctionProps?: lambda.FunctionProps,
/**
* Optional user-provided props to override the default props for the API.
*
Expand All @@ -46,6 +48,8 @@ export interface ApiGatewayToLambdaProps {
*/
export class ApiGatewayToLambda extends Construct {
public readonly apiGateway: api.RestApi;
public readonly apiGatewayCloudWatchRole: iam.Role;
public readonly apiGatewayLogGroup: LogGroup;
public readonly lambdaFunction: lambda.Function;

/**
Expand All @@ -66,6 +70,7 @@ export class ApiGatewayToLambda extends Construct {
});

// Setup the API Gateway
this.apiGateway = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps);
[this.apiGateway, this.apiGatewayCloudWatchRole,
this.apiGatewayLogGroup] = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-solutions-constructs/aws-apigateway-lambda",
"version": "1.52.0",
"version": "1.53.0",
"description": "CDK constructs for defining an interaction between an API Gateway and a Lambda function.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -53,15 +53,16 @@
}
},
"dependencies": {
"@aws-cdk/aws-apigateway": "~1.52.0",
"@aws-cdk/aws-lambda": "~1.52.0",
"@aws-cdk/aws-logs": "~1.52.0",
"@aws-cdk/core": "~1.52.0",
"@aws-solutions-constructs/core": "~1.52.0",
"@aws-cdk/aws-apigateway": "~1.53.0",
"@aws-cdk/aws-lambda": "~1.53.0",
"@aws-cdk/aws-logs": "~1.53.0",
"@aws-cdk/core": "~1.53.0",
"@aws-cdk/aws-iam": "~1.53.0",
"@aws-solutions-constructs/core": "~1.53.0",
"constructs": "^3.0.2"
},
"devDependencies": {
"@aws-cdk/assert": "~1.52.0",
"@aws-cdk/assert": "~1.53.0",
"@types/jest": "^24.0.23",
"@types/node": "^10.3.0"
},
Expand All @@ -71,11 +72,12 @@
]
},
"peerDependencies": {
"@aws-cdk/aws-apigateway": "~1.52.0",
"@aws-cdk/aws-lambda": "~1.52.0",
"@aws-cdk/aws-logs": "~1.52.0",
"@aws-cdk/core": "~1.52.0",
"@aws-solutions-constructs/core": "~1.52.0",
"constructs": "^3.0.2"
"@aws-cdk/aws-apigateway": "~1.53.0",
"@aws-cdk/aws-lambda": "~1.53.0",
"@aws-cdk/aws-logs": "~1.53.0",
"@aws-cdk/core": "~1.53.0",
"@aws-solutions-constructs/core": "~1.53.0",
"constructs": "^3.0.2",
"@aws-cdk/aws-iam": "~1.53.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ test('Test properties', () => {
expect(app.lambdaFunction !== null);
// Assertion 2
expect(app.apiGateway !== null);
expect(app.apiGatewayCloudWatchRole !== null);
expect(app.apiGatewayLogGroup !== null);
});

// --------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ _Parameters_
|:-------------|:----------------|-----------------|
|apiGateway|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApi.html)|Returns an instance of the API Gateway REST API created by the pattern.|
|apiGatewayRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html)|Returns an instance of the iam.Role created by the construct for API Gateway.|
|apiGatewayCloudWatchRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_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/latest/docs/@aws-cdk_aws-logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.|
|sqsQueue|[`sqs.Queue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.Queue.html)|Returns an instance of the SQS queue created by the pattern.|
|deadLetterQueue?|[`sqs.DeadLetterQueue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.DeadLetterQueue.html)|Returns an instance of the DeadLetterQueue created by the pattern.|

## Sample API Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as defaults from '@aws-solutions-constructs/core';
import { Construct } from '@aws-cdk/core';
import * as cdk from '@aws-cdk/core';
import { LogGroup } from '@aws-cdk/aws-logs';

/**
* @summary The properties for the ApiGatewayToSqs class.
Expand All @@ -34,7 +35,7 @@ export interface ApiGatewayToSqsProps {
*
* @default - Default props are used
*/
readonly queueProps?: sqs.QueueProps | any
readonly queueProps?: sqs.QueueProps,
/**
* Whether to deploy a secondary queue to be used as a dead letter queue.
*
Expand Down Expand Up @@ -79,7 +80,10 @@ export interface ApiGatewayToSqsProps {
export class ApiGatewayToSqs extends Construct {
public readonly apiGateway: api.RestApi;
public readonly apiGatewayRole: iam.Role;
public readonly apiGatewayCloudWatchRole: iam.Role;
public readonly apiGatewayLogGroup: LogGroup;
public readonly sqsQueue: sqs.Queue;
public readonly deadLetterQueue?: sqs.DeadLetterQueue;

/**
* @summary Constructs a new instance of the ApiGatewayToSqs class.
Expand All @@ -93,12 +97,11 @@ export class ApiGatewayToSqs extends Construct {
super(scope, id);

// Setup the dead letter queue, if applicable
let dlqi: sqs.DeadLetterQueue | undefined;
if (!props.deployDeadLetterQueue || props.deployDeadLetterQueue === true) {
const dlq: sqs.Queue = defaults.buildQueue(this, 'deadLetterQueue', {
queueProps: props.queueProps
});
dlqi = defaults.buildDeadLetterQueue({
this.deadLetterQueue = defaults.buildDeadLetterQueue({
deadLetterQueue: dlq,
maxReceiveCount: (props.maxReceiveCount) ? props.maxReceiveCount : 3
});
Expand All @@ -107,11 +110,11 @@ export class ApiGatewayToSqs extends Construct {
// Setup the queue
this.sqsQueue = defaults.buildQueue(this, 'queue', {
queueProps: props.queueProps,
deadLetterQueue: dlqi
deadLetterQueue: this.deadLetterQueue
});

// Setup the API Gateway
this.apiGateway = defaults.GlobalRestApi(this);
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this);

// Setup the API Gateway role
this.apiGatewayRole = new iam.Role(this, 'api-gateway-role', {
Expand Down
Loading

0 comments on commit ccf819c

Please sign in to comment.