diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 3634b9aab..90140b121 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -33,7 +33,7 @@ what is the error message you are seeing? - **CDK CLI Version :** - **CDK Framework Version:** - - **Konstruk Version :** + - **AWS Solutions Constructs Version :** - **OS :** - **Language :** diff --git a/CHANGELOG.md b/CHANGELOG.md index f65f0ded8..3ecabe739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,21 @@ 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.46.0] - 2020-06-22 + +General Availability of the AWS Solutions Constructs!! 🎉🎉🥂🥂🍾🍾 + +### Added +- aws-events-rule-step-function pattern added +- aws-s3-step-function pattern added +- Upgraded all patterns to CDK v1.46.0 +- Renamed the Github repo and NPM, PyPi & Maven namespaces to AWS Solutions Constructs + +### Changed +- Changed the default encryption setting for Amazon SQS & Amazon Kinesis to use AWS Managed KMS Key +- Updated READMEs for all patterns to include Default settings section +- For all patterns, converted the getter methods to properties; used for retrieving the underlying AWS Resource object(s) created by the Solutions Constructs + ## [0.8.1-beta] - 2020-05-21 ### Changed - Upgraded to CDK v1.40.0 @@ -14,27 +29,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.8.0-beta] - 2020-03-31 ### Added - Initial public beta release -- aws-apigateway-dynamodb module added -- aws-apigateway-lambda module added -- aws-apigateway-sqs module added -- aws-cloudfront-apigateway-lambda module added -- aws-cloudfront-apigateway module added -- aws-cloudfront-s3 module added -- aws-cognito-apigateway-lambda module added -- aws-dynamodb-stream-lambda-elasticsearch-kibana module added -- aws-dynamodb-stream-lambda module added -- aws-events-rule-lambda module added -- aws-iot-kinesisfirehose-s3 module added -- aws-iot-lambda-dynamodb module added -- aws-iot-lambda module added -- aws-kinesisfirehose-s3-and-kinesisanalytics module added -- aws-kinesisfirehose-s3 module added -- aws-kinesisstreams-lambda module added -- aws-lambda-dynamodb module added -- aws-lambda-elasticsearch-kibana module added -- aws-lambda-s3 module added -- aws-lambda-sns module added -- aws-s3-lambda module added -- aws-sns-lambda module added -- aws-sqs-lambda module added -- core module added +- aws-apigateway-dynamodb pattern added +- aws-apigateway-lambda pattern added +- aws-apigateway-sqs pattern added +- aws-cloudfront-apigateway-lambda pattern added +- aws-cloudfront-apigateway pattern added +- aws-cloudfront-s3 pattern added +- aws-cognito-apigateway-lambda pattern added +- aws-dynamodb-stream-lambda-elasticsearch-kibana pattern added +- aws-dynamodb-stream-lambda pattern added +- aws-events-rule-lambda pattern added +- aws-iot-kinesisfirehose-s3 pattern added +- aws-iot-lambda-dynamodb pattern added +- aws-iot-lambda pattern added +- aws-kinesisfirehose-s3-and-kinesisanalytics pattern added +- aws-kinesisfirehose-s3 pattern added +- aws-kinesisstreams-lambda pattern added +- aws-lambda-dynamodb pattern added +- aws-lambda-elasticsearch-kibana pattern added +- aws-lambda-s3 pattern added +- aws-lambda-sns pattern added +- aws-s3-lambda pattern added +- aws-sns-lambda pattern added +- aws-sqs-lambda pattern added +- core pattern added \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 79071822b..ec5bae250 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ information to effectively respond to your bug report or contribution. We welcome you to use the GitHub issue tracker to report bugs or suggest features. -When filing an issue, please check [existing open](https://github.com/awslabs/aws-solutions-konstruk/issues), or [recently closed](https://github.com/awslabs/aws-solutions-konstruk/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already +When filing an issue, please check [existing open](https://github.com/awslabs/aws-solutions-constructs/issues), or [recently closed](https://github.com/awslabs/aws-solutions-constructs/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: * A reproducible test case or series of steps @@ -21,28 +21,171 @@ reported the issue. Please try to include as much information as you can. Detail ## Contributing via Pull Requests -Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: -1. You are working against the latest source on the *master* branch. -2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. -3. You open an issue to discuss any significant work - we would hate for your time to be wasted. +### Pull Request Checklist + +* [ ] Testing + - Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change) + - Integration test added (if adding a new pattern or making a significant update to an existing pattern) +* [ ] Docs + - __README__: README and/or documentation topic updated + - __Design__: For significant features, design document added to `design` folder +* [ ] Title and Description + - __Change type__: title prefixed with **fix**, **feat** and module name in parens, which will appear in changelog + - __Title__: use lower-case and doesn't end with a period + - __Breaking?__: last paragraph: "BREAKING CHANGE: " + - __Issues__: Indicate issues fixed via: "**Fixes #xxx**" or "**Closes #xxx**" -To send us a pull request, please: +--- -1. Fork the repository. -2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. -3. Ensure local tests pass. -4. Commit to your fork using clear commit messages. -5. Send us a pull request, answering any default questions in the pull request interface. -6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. +### Step 1: Open Issue + +If there isn't one already, open an issue describing what you intend to contribute. It's useful to communicate in +advance, because sometimes, someone is already working in this space, so maybe it's worth collaborating with them +instead of duplicating the efforts. + +### Step 2: Design (optional) + +In some cases, it is useful to seek for feedback by iterating on a design document. This is useful +when you plan a big change or feature, or you want advice on what would be the best path forward. + +Sometimes, the GitHub issue is sufficient for such discussions, and can be sufficient to get +clarity on what you plan to do. Sometimes, a design document would work better, so people can provide +iterative feedback. + +In such cases, use the GitHub issue description to collect **requirements** and +**use cases** for your feature. + +Then, create a design document in markdown format under the `design/` directory +and request feedback through a pull request. + +Once the design is finalized, you can re-purpose this PR for the implementation, +or open a new PR to that end. + +### Step 3: Work your Magic + +Work your magic. Here are some guidelines: + +* Coding style (abbreviated): + * In general, follow the style of the code around you + * 2 space indentation + * 120 characters wide + * ATX style headings in markdown (e.g. `## H2 heading`) +* Every change requires a unit test +* If you change APIs, make sure to update the module's README file +* Try to maintain a single feature/bugfix per pull request. It's okay to introduce a little bit of housekeeping + changes along the way, but try to avoid conflating multiple features. Eventually all these are going to go into a + single commit, so you can use that to frame your scope. +* If your change introduces a new construct, take a look at the our + [aws-apigateway-lambd Construct](https://github.com/awslabs/aws-solutions-constructs/tree/master/source/patterns/%40aws-solutions-constructs/aws-apigateway-lambda) for an explanation of the L3 patterns we use. + Feel free to start your contribution by copy&pasting files from that project, + and then edit and rename them as appropriate - + it might be easier to get started that way. + +#### Integration Tests + +Integration tests perform a few functions in the CDK code base - +1. Acts as a regression detector. It does this by running `cdk synth` on the integration test and comparing it against + the `*.expected.json` file. This highlights how a change affects the synthesized stacks. +2. Allows for a way to verify if the stacks are still valid CloudFormation templates, as part of an intrusive change. + This is done by running `yarn integ` which will run `cdk deploy` across all of the integration tests in that package. + Remember to set up AWS credentials before doing this. +3. (Optionally) Acts as a way to validate that constructs set up the CloudFormation resources as expected. A successful + CloudFormation deployment does not mean that the resources are set up correctly. + +If you are working on a new feature that is using previously unused CloudFormation resource types, or involves +configuring resource types across services, you need to write integration tests that use these resource types or +features. + +To the extent possible, include a section (like below) in the integration test file that specifies how the successfully +deployed stack can be verified for correctness. Correctness here implies that the resources have been set up correctly. +The steps here are usually AWS CLI commands but they need not be. + +```ts +/* + * Stack verification steps: + * * + * * + */ +``` + +Examples: +* [integ.deployFunction.ts](https://github.com/awslabs/aws-solutions-constructs/blob/master/source/patterns/%40aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.ts) +* [integ.existingFunction.ts](https://github.com/awslabs/aws-solutions-constructs/blob/master/source/patterns/%40aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.ts) + +### Step 4: Commit + +Create a commit with the proposed changes: + +* Commit title and message (and PR title and description) must adhere to [conventionalcommits](https://www.conventionalcommits.org). + * The title must begin with `feat(module): title`, `fix(module): title`, `refactor(module): title` or + `chore(module): title`. + * Title should be lowercase. + * No period at the end of the title. + +* Commit message should describe _motivation_. Think about your code reviewers and what information they need in + order to understand what you did. If it's a big commit (hopefully not), try to provide some good entry points so + it will be easier to follow. + +* Commit message should indicate which issues are fixed: `fixes #` or `closes #`. + +* Shout out to collaborators. + +* If not obvious (i.e. from unit tests), describe how you verified that your change works. + +* If this commit includes breaking changes, they must be listed at the end in the following format (notice how multiple breaking changes should be formatted): + +``` +BREAKING CHANGE: Description of what broke and how to achieve this behavior now +* **module-name:** Another breaking change +* **module-name:** Yet another breaking change +``` + +### Step 5: Pull Request + +* Push to a GitHub fork or to a branch (naming convention: `/`) +* Submit a Pull Requests on GitHub. +* Please follow the PR checklist written below. We trust our contributors to self-check, and this helps that process! +* Discuss review comments and iterate until you get at least one “Approve”. When iterating, push new commits to the + same branch. Usually all these are going to be squashed when you merge to master. The commit messages should be hints + for you when you finalize your merge commit message. +* Make sure to update the PR title/description if things change. The PR title/description are going to be used as the + commit title/message and will appear in the CHANGELOG, so maintain them all the way throughout the process. + + + +### Step 6: Merge + +* Make sure your PR builds successfully (we have CodeBuild setup to automatically build all PRs) +* Once approved and tested, a maintainer will squash-merge to master and will use your PR title/description as the + commit message. GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). +## Building Pattern(s) + +### Full Build + +```console +$ cd +$ docker run --rm --net=host -it -v $PWD:$PWD -w $PWD jsii/superchain +docker$ cd deployment +docker$ ./build-patterns.sh +docker$ exit +``` + +### Partial Build -## Finding contributions to work on -Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-solutions-konstruk/labels/help%20wanted) issues is a great place to start. +First run a clean Full Build before doing the partial build. +```console +$ cd +$ docker run --rm --net=host -it -v $PWD:$PWD -w $PWD jsii/superchain +docker$ cd source/patterns/@aws-solutions-constructs/my-module +docker$ npm run build+lint+test +docker$ exit +``` ## Code of Conduct This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). @@ -56,6 +199,6 @@ If you discover a potential security issue in this project we ask that you notif ## Licensing -See the [LICENSE](https://github.com/awslabs/aws-solutions-konstruk/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. +See the [LICENSE](https://github.com/awslabs/aws-solutions-constructs/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. diff --git a/NOTICE.txt b/NOTICE.txt index 833fe2b9f..60c18149b 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,4 +1,4 @@ -AWS Konstruk +AWS Solutions Constructs Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://www.apache.org/licenses/ diff --git a/README.md b/README.md index e0bce0513..e06a5ab9d 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,25 @@ -# API Reference - +# AWS Solutions Constructs ---- - -![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) - -> **This is a _developer preview_ (public beta) library.** -> -> All modules are under active development and subject to non-backward compatible changes or removal in any -> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. -> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. - ---- - - -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
-The AWS Solutions Konstruk Library (Konstruk) is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions in code to create predictable and repeatable infrastructure. Konstruk's goal is to accelerates the experience for developers to build solutions of any size using pattern-based definitions for their architecture. +The AWS Solutions Constructs library is an open-source extension of the AWS Cloud Development Kit (AWS CDK) that provides multi-service, well-architected patterns for quickly defining solutions in code to create predictable and repeatable infrastructure. The goal of AWS Solutions Constructs is to accelerate the experience for developers to build solutions of any size using pattern-based definitions for their architecture. -The patterns defined in Konstruk are high level, multi-service abstractions of AWS CDK constructs that have default configurations based on well-architected best practices. The library is organized into logical modules using object-oriented techniques to create each architectural pattern model. +The patterns defined in AWS Solutions Constructs are high level, multi-service abstractions of AWS CDK constructs that have default configurations based on well-architected best practices. The library is organized into logical modules using object-oriented techniques to create each architectural pattern model. The CDK is available in the following languages: -* JavaScript, TypeScript (Node.js ≥ 10.3.0) +* JavaScript, TypeScript (Node.js ≥ 10.13.0) * Python (Python ≥ 3.6) +* Java (Java ≥ 8 and Maven ≥ 3.5.4) ## Modules -The Konstruk library is organized into several modules. They are named like this: +The AWS Solutions Constructs library is organized into several modules. They are named like this: * __aws-xxx__: well architected pattern package for the indicated services. This package will contain constructs that contain multiple AWS CDK service modules to configure the given pattern. -* __xxx__: packages that don't start "aws-" are Konstruk core modules that are used to configure best practice defaults for services used within the pattern library. +* __xxx__: packages that don't start "aws-" are core modules that are used to configure best practice defaults for services used within the pattern library. ## Module Contents @@ -47,14 +34,14 @@ The pattern's documentation page also lists the available methods to call and th ## Sample Use Cases -This library includes a collection of functional use case implementations to demonstrate the usage of Konstruk architectural patterns. These can be used in the same way as architectural patterns, and can be conceptualized as an additional "higher-level" abstraction of those patterns. The following use cases are provided as functional examples: +This library includes a collection of functional use case implementations to demonstrate the usage of AWS Solutions Constructs architectural patterns. These can be used in the same way as architectural patterns, and can be conceptualized as an additional "higher-level" abstraction of those patterns. The following use cases are provided as functional examples: * __aws-s3-static-website__ - implements an Amazon CloudFront distribution, Amazon S3 bucket and AWS Lambda-based custom resource to copy the static website content for the Wild Rydes demo website (part of the aws-serverless-web-app implementation). - * Use case pattern: https://github.com/awslabs/aws-solutions-konstruk/source/use_cases/aws-s3-static-website + * Use case pattern: https://github.com/awslabs/aws-solutions-constructs/tree/master/source/use_cases/aws-s3-static-website * __aws-serverless-image-handler__ - implements an Amazon CloudFront distribution, an Amazon API Gateway REST API, an AWS Lambda function, and necessary permissions/logic to provision a functional image handler API for serving image content from one or more Amazon S3 buckets within the deployment account. - * Use case pattern: https://github.com/awslabs/aws-solutions-konstruk/source/use_cases/aws-serverless-image-handler + * Use case pattern: https://github.com/awslabs/aws-solutions-constructs/tree/master/source/use_cases/aws-serverless-image-handler * __aws-serverless-web-app__ - implements a simple serverless web application that enables users to request unicorn rides from the Wild Rydes fleet. The application will present users with an HTML based user interface for indicating the location where they would like to be picked up and will interface on the backend with a RESTful web service to submit the request and dispatch a nearby unicorn. The application will also provide facilities for users to register with the service and log in before requesting rides. - * Use case pattern: https://github.com/awslabs/aws-solutions-konstruk/source/use_cases/aws-serverless-web-app + * Use case pattern: https://github.com/awslabs/aws-solutions-constructs/tree/master/source/use_cases/aws-serverless-web-app *** © Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/source/lerna.json b/source/lerna.json index cb6781ba1..9812c6adf 100644 --- a/source/lerna.json +++ b/source/lerna.json @@ -3,9 +3,8 @@ "npmClient": "yarn", "useWorkspaces": true, "packages": [ - "./patterns/@aws-solutions-konstruk/*", - "./use_cases/*" + "./patterns/@aws-solutions-constructs/*" ], "rejectCycles": "true", - "version": "0.8.1" + "version": "1.46.0" } diff --git a/source/package.json b/source/package.json index e709e1248..fd2c4c27c 100644 --- a/source/package.json +++ b/source/package.json @@ -1,10 +1,10 @@ { - "name": "aws-solutions-konstruk", - "version": "0.8.1", - "description": "AWS Solutions Konstruk Library", + "name": "aws-solutions-constructs", + "version": "1.46.0", + "description": "AWS Solutions Constructs Library", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", "directory": "source" }, "license": "Apache-2.0", @@ -23,18 +23,17 @@ "eslint-plugin-license-header": "^0.2.0", "fs-extra": "^8.1.0", "jest": "^24.9.0", - "jsii": "^1.4.1", - "jsii-pacmak": "^1.4.1", + "jsii": "^1.7.0", + "jsii-pacmak": "^1.7.0", "tslint": "^5.20.1", - "typescript": "~3.8.3" + "typescript": "~3.9.5" }, "devDependencies": { - "lerna": "^3.18.4" + "lerna": "^3.22.1" }, "workspaces": { "packages": [ - "./patterns/@aws-solutions-konstruk/*", - "./use_cases/*" + "./patterns/@aws-solutions-constructs/*" ], "nohoist": [ "**/deepmerge", diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.gitignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.npmignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/README.md rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md index b551ac27b..58480e96f 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,23 +12,24 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-apigateway-dynamodb/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_apigateway_dynamodb`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-apigateway-dynamodb`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_apigateway_dynamodb`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-apigateway-dynamodb`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.apigatewaydynamodb`| ## Overview -This AWS Solutions Konstruk implements an Amazon API Gateway REST API connected to Amazon DynamoDB table. +This AWS Solutions Construct implements an Amazon API Gateway REST API connected to Amazon DynamoDB table. Here is a minimal deployable pattern definition: ``` javascript -import { ApiGatewayToDynamoDBProps, ApiGatewayToDynamoDB } from "@aws-solutions-konstruk/aws-apigateway-dynamodb"; +import { ApiGatewayToDynamoDBProps, ApiGatewayToDynamoDB } from "@aws-solutions-constructs/aws-apigateway-dynamodb"; const props: ApiGatewayToDynamoDBProps = {}; @@ -56,19 +55,36 @@ _Parameters_ |:-------------|:----------------|-----------------| |dynamoTableProps|[`dynamodb.TableProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.TableProps.html)|Optional user provided props to override the default props for DynamoDB Table| |apiGatewayProps?|[`api.RestApiProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApiProps.html)|Optional user-provided props to override the default props for the API Gateway.| -|allowCreateOperation|`boolean`|Whether to deploy API Gateway Method for Create operation on Dynamodb DB table.| +|allowCreateOperation|`boolean`|Whether to deploy API Gateway Method for Create operation on DynamoDB table.| |createRequestTemplate|`string`|API Gateway Request template for Create method, required if allowCreateOperation set to true| -|allowReadOperation|`boolean`|Whether to deploy API Gateway Method for Read operation on Dynamodb DB table.| -|allowUpdateOperation|`boolean`|Whether to deploy API Gateway Method for Update operation on Dynamodb DB table.| +|allowReadOperation|`boolean`|Whether to deploy API Gateway Method for Read operation on DynamoDB table.| +|allowUpdateOperation|`boolean`|Whether to deploy API Gateway Method for Update operation on DynamoDB table.| |updateRequestTemplate|`string`|API Gateway Request template for Update method, required if allowUpdateOperation set to true| -|allowDeleteOperation|`boolean`|Whether to deploy API Gateway Method for Delete operation on Dynamodb DB table.| +|allowDeleteOperation|`boolean`|Whether to deploy API Gateway Method for Delete operation on DynamoDB table.| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|restApi()|[`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.| -|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.| +|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.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon API Gateway +* Deploy an edge-optimized API endpoint +* Enable CloudWatch logging for API Gateway +* Configure least privilege access IAM role for API Gateway +* Set the default authorizationType for all API methods to IAM + +### Amazon DynamoDB Table +* Set the billing mode for DynamoDB Table to On-Demand (Pay per request) +* Enable server-side encryption for DynamoDB Table using AWS managed KMS Key +* Creates a partition key called 'id' for DynamoDB Table +* Retain the Table when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/architecture.png b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/lib/index.ts similarity index 79% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/lib/index.ts index b4a72ae80..608b51a60 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/lib/index.ts @@ -13,10 +13,10 @@ import * as api from '@aws-cdk/aws-apigateway'; import * as iam from '@aws-cdk/aws-iam'; -import * as defaults from '@aws-solutions-konstruk/core'; +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-konstruk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; /** * @summary The properties for the ApiGatewayToDynamoDB class. @@ -36,7 +36,7 @@ export interface ApiGatewayToDynamoDBProps { readonly apiGatewayProps?: api.RestApiProps | any, /** - * Whether to deploy API Gateway Method for Create operation on Dynamodb DB table. + * Whether to deploy API Gateway Method for Create operation on DynamoDB table. * * @default - false */ @@ -50,14 +50,14 @@ export interface ApiGatewayToDynamoDBProps { readonly createRequestTemplate?: string, /** - * Whether to deploy API Gateway Method for Read operation on Dynamodb DB table. + * Whether to deploy API Gateway Method for Read operation on DynamoDB table. * * @default - true */ readonly allowReadOperation?: boolean, /** - * Whether to deploy API Gateway Method for Update operation on Dynamodb DB table. + * Whether to deploy API Gateway Method for Update operation on DynamoDB table. * * @default - false */ @@ -71,7 +71,7 @@ export interface ApiGatewayToDynamoDBProps { readonly updateRequestTemplate?: string, /** - * Whether to deploy API Gateway Method for Delete operation on Dynamodb DB table. + * Whether to deploy API Gateway Method for Delete operation on DynamoDB table. * * @default - false */ @@ -82,9 +82,9 @@ export interface ApiGatewayToDynamoDBProps { * @summary The ApiGatewayToDynamoDB class. */ export class ApiGatewayToDynamoDB extends Construct { - private table: dynamodb.Table; - private apiGatewayRole: iam.Role; - private apiGateway: api.RestApi; + public readonly dynamoTable: dynamodb.Table; + public readonly apiGatewayRole: iam.Role; + public readonly apiGateway: api.RestApi; /** * @summary Constructs a new instance of the ApiGatewayToDynamoDB class. @@ -102,10 +102,10 @@ export class ApiGatewayToDynamoDB extends Construct { if (props.dynamoTableProps) { const dynamoTableProps: dynamodb.TableProps = overrideProps(defaults.DefaultTableProps, props.dynamoTableProps); partitionKeyName = dynamoTableProps.partitionKey.name; - this.table = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); } else { partitionKeyName = defaults.DefaultTableProps.partitionKey.name; - this.table = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableProps); } // Setup the API Gateway @@ -122,25 +122,25 @@ export class ApiGatewayToDynamoDB extends Construct { // Setup API Gateway Method // Create if (props.allowCreateOperation && props.allowCreateOperation === true && props.createRequestTemplate) { - const createRequestTemplate = props.createRequestTemplate.replace("${Table}", this.table.tableName); + const createRequestTemplate = props.createRequestTemplate.replace("${Table}", this.dynamoTable.tableName); this.addActiontoPlicy("dynamodb:PutItem"); this.addMethod(this.apiGateway.root, createRequestTemplate, "PutItem", "POST"); } // Read if (!props.allowReadOperation || props.allowReadOperation === true) { - const getRequestTemplate = "{\r\n\"TableName\": \"" + this.table.tableName + "\",\r\n \"KeyConditionExpression\": \"" + partitionKeyName + " = :v1\",\r\n \"ExpressionAttributeValues\": {\r\n \":v1\": {\r\n \"S\": \"$input.params('" + partitionKeyName + "')\"\r\n }\r\n }\r\n}"; + 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.addMethod(apiGatewayResource, getRequestTemplate, "Query", "GET"); } // Update if (props.allowUpdateOperation && props.allowUpdateOperation === true && props.updateRequestTemplate) { - const updateRequestTemplate = props.updateRequestTemplate.replace("${Table}", this.table.tableName); + const updateRequestTemplate = props.updateRequestTemplate.replace("${Table}", this.dynamoTable.tableName); this.addActiontoPlicy("dynamodb:UpdateItem"); this.addMethod(apiGatewayResource, updateRequestTemplate, "UpdateItem", "PUT"); } // Delete if (props.allowDeleteOperation && props.allowDeleteOperation === true) { - const deleteRequestTemplate = "{\r\n \"TableName\": \"" + this.table.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}"; + 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.addMethod(apiGatewayResource, deleteRequestTemplate, "DeleteItem", "DELETE"); } @@ -149,7 +149,7 @@ export class ApiGatewayToDynamoDB extends Construct { private addActiontoPlicy(action: string) { this.apiGatewayRole.addToPolicy(new iam.PolicyStatement({ resources: [ - this.table.tableArn + this.dynamoTable.tableArn ], actions: [ `${action}` ] })); @@ -203,24 +203,4 @@ export class ApiGatewayToDynamoDB extends Construct { ] }); } - - /** - * @summary Returns an instance of the api.RestApi created by the construct. - * @returns {api.RestApi} Instance of the RestApi created by the construct. - * @since 0.8.0 - * @access public - */ - public restApi(): api.RestApi { - return this.apiGateway; - } - - /** - * @summary Returns an instance of dynamodb.Table created by the construct. - * @returns {dynamodb.Table} Instance of dynamodb.Table created by the construct - * @since 0.8.0 - * @access public - */ - public dynamoTable(): dynamodb.Table { - return this.table; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/package.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/package.json similarity index 59% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/package.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/package.json index fd384e38d..9eb69d9c8 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-apigateway-dynamodb", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-apigateway-dynamodb", + "version": "1.46.0", "description": "CDK Constructs for AWS API Gateway and Amazon DynamoDB integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.apigatewaydynamodb", + "package": "software.amazon.awsconstructs.services.apigatewaydynamodb", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "apigatewaydynamodb" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.ApiGatewayDynamoDB", - "packageId": "Amazon.Konstruk.AWS.ApiGatewayDynamoDB", + "namespace": "Amazon.Constructs.AWS.ApiGatewayDynamoDB", + "packageId": "Amazon.Constructs.AWS.ApiGatewayDynamoDB", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-apigateway-dynamodb", - "module": "aws_solutions_konstruk.aws_apigateway_dynamodb" + "distName": "aws-solutions-constructs.aws-apigateway-dynamodb", + "module": "aws_solutions_constructs.aws_apigateway_dynamodb" } } }, "dependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/__snapshots__/apigateway-dynamodb.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/__snapshots__/apigateway-dynamodb.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/__snapshots__/apigateway-dynamodb.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/__snapshots__/apigateway-dynamodb.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts index 7a01ccad7..884fb196e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/apigateway-dynamodb.test.ts @@ -25,13 +25,14 @@ test('snapshot test ApiGatewayToDynamoDB default params', () => { expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new Stack(); const apiGatewayToDynamoDBProps: ApiGatewayToDynamoDBProps = {}; const construct = new ApiGatewayToDynamoDB(stack, 'test-api-gateway-dynamodb-default', apiGatewayToDynamoDBProps); - expect(construct.dynamoTable()).toBeDefined(); - expect(construct.restApi()).toBeDefined(); + expect(construct.dynamoTable !== null); + expect(construct.apiGateway !== null); + expect(construct.apiGatewayRole !== null); }); test('check allow CRUD operations', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-CRUD.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-dynamodb/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md similarity index 64% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md index 3de5d141c..edffd7f49 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,23 +12,24 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-apigateway-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_apigateway_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-apigateway-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_apigateway_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-apigateway-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.apigatewaylambda`| ## Overview -This AWS Solutions Konstruk implements an Amazon API Gateway REST API connected to an AWS Lambda function pattern. +This AWS Solutions Construct implements an Amazon API Gateway REST API connected to an AWS Lambda function pattern. Here is a minimal deployable pattern definition: ``` javascript -const { ApiGatewayToLambda } = require('@aws-solutions-konstruk/aws-apigateway-lambda'); +const { ApiGatewayToLambda } = require('@aws-solutions-constructs/aws-apigateway-lambda'); new ApiGatewayToLambda(stack, 'ApiGatewayToLambdaPattern', { deployLambda: true, @@ -68,8 +67,22 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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.| +|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.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon API Gateway +* Deploy an edge-optimized API endpoint +* Enable CloudWatch logging for API Gateway +* Configure least privilege access IAM role for API Gateway +* Set the default authorizationType for all API methods to IAM + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/lib/index.ts similarity index 74% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/lib/index.ts index a461340b6..874b72d9c 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/lib/index.ts @@ -14,7 +14,7 @@ // Imports import * as api from '@aws-cdk/aws-apigateway'; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -54,9 +54,8 @@ export interface ApiGatewayToLambdaProps { * @summary The ApiGatewayToLambda class. */ export class ApiGatewayToLambda extends Construct { - // Private variables - private api: api.RestApi; - private fn: lambda.Function; + public readonly apiGateway: api.RestApi; + public readonly lambdaFunction: lambda.Function; /** * @summary Constructs a new instance of the ApiGatewayToLambda class. @@ -70,33 +69,13 @@ export class ApiGatewayToLambda extends Construct { super(scope, id); // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); // Setup the API Gateway - this.api = defaults.GlobalLambdaRestApi(this, this.fn, props.apiGatewayProps); - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns { lambda.Function } Instance of Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of api.LambdaRestApi created by the construct. - * @returns { api.LambdaRestApi } Instance of LambdaRestApi created by the construct - * @since 0.8.0 - * @access public - */ - public restApi(): api.LambdaRestApi { - return this.api; + this.apiGateway = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps); } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/package.json similarity index 59% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/package.json index 5b4a2d6dc..21375230f 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-apigateway-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-apigateway-lambda", + "version": "1.46.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", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-apigateway-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.apigatewaylambda", + "package": "software.amazon.awsconstructs.services.apigatewaylambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "apigatewaylambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.ApiGatewayLambda", - "packageId": "Amazon.Konstruk.AWS.ApiGatewayLambda", + "namespace": "Amazon.Constructs.AWS.ApiGatewayLambda", + "packageId": "Amazon.Constructs.AWS.ApiGatewayLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-apigateway-lambda", - "module": "aws_solutions_konstruk.aws_apigateway_lambda" + "distName": "aws-solutions-constructs.aws-apigateway-lambda", + "module": "aws_solutions_constructs.aws_apigateway_lambda" } } }, "dependencies": { - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap index 9596458f6..fdceec1f4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/__snapshots__/test.apigateway-lambda.test.js.snap @@ -450,7 +450,7 @@ Object { Object { "Ref": "testapigatewaylambdaLambdaRestApiE957E944", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -491,7 +491,7 @@ Object { Object { "Ref": "testapigatewaylambdaLambdaRestApiDeploymentStageprod4EBF7247", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -1027,7 +1027,7 @@ Object { Object { "Ref": "testapigatewaylambdaLambdaRestApiE957E944", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -1068,7 +1068,7 @@ Object { Object { "Ref": "testapigatewaylambdaLambdaRestApiDeploymentStageprod4EBF7247", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -1670,7 +1670,7 @@ Object { Object { "Ref": "pattern1LambdaRestApi6083801A", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -1711,7 +1711,7 @@ Object { Object { "Ref": "pattern1LambdaRestApiDeploymentStageprodFF2B9A97", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -2198,7 +2198,7 @@ Object { Object { "Ref": "pattern2LambdaRestApi7106C394", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -2239,7 +2239,7 @@ Object { Object { "Ref": "pattern2LambdaRestApiDeploymentStageprod134BC514", }, - "/*/{proxy+}", + "/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.deployFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.expected.json similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.deployFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.expected.json index 316c3cbc5..4adc6b950 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.deployFunction.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.expected.json @@ -240,7 +240,7 @@ { "Ref": "testapigatewaylambdaLambdaRestApiDeploymentStageprod4EBF7247" }, - "/*/{proxy+}" + "/*/*" ] ] } @@ -277,7 +277,7 @@ { "Ref": "testapigatewaylambdaLambdaRestApiE957E944" }, - "/test-invoke-stage/*/{proxy+}" + "/test-invoke-stage/*/*" ] ] } diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.deployFunction.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.deployFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.deployFunction.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.expected.json similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.expected.json index a158223f0..537702bee 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.expected.json @@ -240,7 +240,7 @@ { "Ref": "testapigatewaylambdaLambdaRestApiDeploymentStageprod4EBF7247" }, - "/*/{proxy+}" + "/*/*" ] ] } @@ -277,7 +277,7 @@ { "Ref": "testapigatewaylambdaLambdaRestApiE957E944" }, - "/test-invoke-stage/*/{proxy+}" + "/test-invoke-stage/*/*" ] ] } diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.ts index 5d311aa88..f9d44698e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/integ.existingFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/integ.existingFunction.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { ApiGatewayToLambda, ApiGatewayToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // App setup const app = new App(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts index 56ee9442c..cadf21df4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/test/test.apigateway-lambda.test.ts @@ -96,13 +96,13 @@ test('Test deployLambda=true with lambdaFunctionProps', () => { }; const app = new ApiGatewayToLambda(stack, 'test-apigateway-lambda', props); // Assertion 1 - expect(app.lambdaFunction()).toHaveProperty('environment.OVERRIDE_STATUS', 'true'); + expect(app.lambdaFunction).toHaveProperty('environment.OVERRIDE_STATUS', 'true'); }); // -------------------------------------------------------------- // Test getter methods // -------------------------------------------------------------- -test('Test getter methods', () => { +test('Test properties', () => { // Initial Setup const stack = new Stack(); const props: ApiGatewayToLambdaProps = { @@ -115,9 +115,9 @@ test('Test getter methods', () => { }; const app = new ApiGatewayToLambda(stack, 'test-apigateway-lambda', props); // Assertion 1 - expect(app.lambdaFunction()).toBeDefined(); + expect(app.lambdaFunction !== null); // Assertion 2 - expect(app.restApi()).toBeDefined(); + expect(app.apiGateway !== null); }); // -------------------------------------------------------------- diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.gitignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.npmignore b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md similarity index 55% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/README.md rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md index cdfb9e4fd..1df8171b4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,28 +12,28 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-apigateway-sqs/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_apigateway_sqs`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-apigateway-sqs`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_apigateway_sqs`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-apigateway-sqs`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.apigatewaysqs`| ## Overview -This AWS Solutions Konstruk implements an Amazon API Gateway connected to an Amazon SQS queue pattern. +This AWS Solutions Construct implements an Amazon API Gateway connected to an Amazon SQS queue pattern. Here is a minimal deployable pattern definition: ``` javascript -const { ApiGatewayToSqs } = require('@aws-solutions-konstruk/aws-apigateway-sqs'); +const { ApiGatewayToSqs } = require('@aws-solutions-constructs/aws-apigateway-sqs'); new ApiGatewayToSqs(stack, 'ApiGatewayToSqsPattern', { apiGatewayProps: {}, queueProps: {}, - encryptionKeyProps: {}, deployDeadLetterQueue?: true, maxReceiveCount?: 3 }); @@ -60,16 +58,20 @@ _Parameters_ |:-------------|:----------------|-----------------| |apiGatewayProps?|[`api.RestApiProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApiProps.html)|Optional user-provided props to override the default props for the API Gateway.| |queueProps?|[`sqs.QueueProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.QueueProps.html)|Optional user-provided props to override the default props for the queue.| -|encryptionKeyProps?|[`kms.KeyProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kms.KeyProps.html)|Optional user-provided props to override the default props for the encryption key.| |deployDeadLetterQueue|`boolean`|Whether to deploy a secondary queue to be used as a dead letter queue.| -|maxReceiveCount|`number`|The number of times a message can be unsuccesfully dequeued before being moved to the dead-letter queue.| +|maxReceiveCount|`number`|The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue.| +|allowCreateOperation?|`boolean`|Whether to deploy an API Gateway Method for Create operations on the queue (i.e. sqs:SendMessage).| +|createRequestTemplate?|`string`|API Gateway Request template for Create method, required if allowCreateOperation set to true.| +|allowReadOperation?|`boolean`|Whether to deploy an API Gateway Method for Read operations on the queue (i.e. sqs:ReceiveMessage).| +|allowDeleteOperation?|`boolean`|Whether to deploy an API Gateway Method for Delete operations on the queue (i.e. sqs:DeleteMessage).| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|api()|[`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.| -|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.| +|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.| +|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.| ## Sample API Usage @@ -79,6 +81,20 @@ _Parameters_ |POST|`/`| `{ "data": "Hello World!" }` |`sqs::SendMessage`|Delivers a message to the queue.| |DELETE|`/message?receiptHandle=[value]`||`sqs::DeleteMessage`|Deletes a specified message from the queue| +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon API Gateway +* Deploy an edge-optimized API endpoint +* Enable CloudWatch logging for API Gateway +* Configure least privilege access IAM role for API Gateway +* Set the default authorizationType for all API methods to IAM + +### Amazon SQS Queue +* Deploy SQS dead-letter queue for the source SQS Queue +* Enable server-side encryption for source SQS Queue using AWS Managed KMS Key + ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/architecture.png b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/lib/index.ts similarity index 80% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/lib/index.ts index 22f53eeef..ee8de6615 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/lib/index.ts @@ -14,9 +14,8 @@ // Imports import * as api from '@aws-cdk/aws-apigateway'; import * as sqs from '@aws-cdk/aws-sqs'; -import * as kms from '@aws-cdk/aws-kms'; import * as iam from '@aws-cdk/aws-iam'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; import * as cdk from '@aws-cdk/core'; @@ -36,12 +35,6 @@ export interface ApiGatewayToSqsProps { * @default - Default props are used */ readonly queueProps?: sqs.QueueProps | any - /** - * Optional user-provided props to override the default props for the encryption key. - * - * @default - Default props are used - */ - readonly encryptionKeyProps?: kms.KeyProps | any /** * Whether to deploy a secondary queue to be used as a dead letter queue. * @@ -49,7 +42,7 @@ export interface ApiGatewayToSqsProps { */ readonly deployDeadLetterQueue?: boolean, /** - * The number of times a message can be unsuccesfully dequeued before being moved to the dead-letter queue. + * The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue. * * @default - required only if deployDeadLetterQueue = true. */ @@ -84,11 +77,9 @@ export interface ApiGatewayToSqsProps { * @summary The ApiGatewayToSqs class. */ export class ApiGatewayToSqs extends Construct { - // Private variables - private encryptionKey: kms.Key; - private apiGateway: api.RestApi; - private apiGatewayRole: iam.Role; - private queue: sqs.Queue; + public readonly apiGateway: api.RestApi; + public readonly apiGatewayRole: iam.Role; + public readonly sqsQueue: sqs.Queue; /** * @summary Constructs a new instance of the ApiGatewayToSqs class. @@ -101,14 +92,10 @@ export class ApiGatewayToSqs extends Construct { constructor(scope: Construct, id: string, props: ApiGatewayToSqsProps) { super(scope, id); - // Setup the encryption key - this.encryptionKey = defaults.buildEncryptionKey(this, props.encryptionKeyProps); - // 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', { - encryptionKey: this.encryptionKey, queueProps: props.queueProps }); dlqi = defaults.buildDeadLetterQueue({ @@ -118,8 +105,7 @@ export class ApiGatewayToSqs extends Construct { } // Setup the queue - this.queue = defaults.buildQueue(this, 'queue', { - encryptionKey: this.encryptionKey, + this.sqsQueue = defaults.buildQueue(this, 'queue', { queueProps: props.queueProps, deadLetterQueue: dlqi }); @@ -135,9 +121,6 @@ export class ApiGatewayToSqs extends Construct { // Setup the API Gateway resource const apiGatewayResource = this.apiGateway.root.addResource('message'); - // Grant encrypt/decrypt permissions for the API Gateway via KMS - this.encryptionKey.grantEncryptDecrypt(this.apiGatewayRole); - // Setup API Gateway methods // Create if (props.allowCreateOperation && props.allowCreateOperation === true && props.createRequestTemplate) { @@ -162,7 +145,7 @@ export class ApiGatewayToSqs extends Construct { private addActionToPolicy(action: string) { this.apiGatewayRole.addToPolicy(new iam.PolicyStatement({ resources: [ - this.queue.queueArn + this.sqsQueue.queueArn ], actions: [ `${action}` ] })); @@ -172,7 +155,7 @@ export class ApiGatewayToSqs extends Construct { // Add the integration const apiGatewayIntegration = new api.AwsIntegration({ service: "sqs", - path: `${cdk.Aws.ACCOUNT_ID}/${this.queue.queueName}`, + path: `${cdk.Aws.ACCOUNT_ID}/${this.sqsQueue.queueName}`, integrationHttpMethod: "POST", options: { passthroughBehavior: api.PassthroughBehavior.NEVER, @@ -217,24 +200,4 @@ export class ApiGatewayToSqs extends Construct { ] }); } - - /** - * @summary Returns an instance of the api.RestApi created by the construct. - * @returns {api.RestApi} Instance of the RestApi created by the construct. - * @since 0.8.0 - * @access public - */ - public api(): api.RestApi { - return this.apiGateway; - } - - /** - * @summary Returns an instance of the sqs.Queue created by the construct. - * @returns {sqs.Queue} Instance of the Queue created by the construct. - * @since 0.8.0 - * @access public - */ - public sqsQueue(): sqs.Queue { - return this.queue; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/package.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/package.json similarity index 57% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/package.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/package.json index f43cb2d80..fd7468e05 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-apigateway-sqs", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-apigateway-sqs", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an AWS Lambda function and an Amazon S3 bucket.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-apigateway-sqs" }, "author": { "name": "Amazon Web Services", @@ -24,6 +24,7 @@ "watch": "tsc -b -w", "integ": "cdk-integ", "integ-assert": "cdk-integ-assert", + "integ-no-clean": "cdk-integ --no-clean", "jsii": "jsii", "jsii-pacmak": "jsii-pacmak", "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", @@ -33,35 +34,35 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.apigatewaysqs", + "package": "software.amazon.awsconstructs.services.apigatewaysqs", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "apigatewaysqs" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.ApiGatewaySqs", - "packageId": "Amazon.Konstruk.AWS.ApiGatewaySqs", + "namespace": "Amazon.Constructs.AWS.ApiGatewaySqs", + "packageId": "Amazon.Constructs.AWS.ApiGatewaySqs", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-apigateway-sqs", - "module": "aws_solutions_konstruk.aws_apigateway_sqs" + "distName": "aws-solutions-constructs.aws-apigateway-sqs", + "module": "aws_solutions_constructs.aws_apigateway_sqs" } } }, "dependencies": { - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,12 +72,12 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap similarity index 83% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap index 2da122a15..752617217 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/__snapshots__/apigateway-sqs.test.js.snap @@ -36,76 +36,6 @@ Object { "Type": "AWS::Logs::LogGroup", "UpdateReplacePolicy": "Retain", }, - "apigatewaysqsEncryptionKey4A698F7C": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsapigatewayrole2BA120D3", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "apigatewaysqsLambdaRestApiAccount8FA59342": Object { "DependsOn": Array [ "apigatewaysqsRestApi03BFD711", @@ -544,21 +474,6 @@ Object { "Properties": Object { "PolicyDocument": Object { "Statement": Array [ - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, - }, Object { "Action": "sqs:SendMessage", "Effect": "Allow", @@ -603,23 +518,13 @@ Object { }, "apigatewaysqsdeadLetterQueue25B510FA": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", }, "Type": "AWS::SQS::Queue", }, "apigatewaysqsqueueE186B895": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": Object { "deadLetterTargetArn": Object { "Fn::GetAtt": Array [ @@ -672,76 +577,6 @@ Object { "Type": "AWS::Logs::LogGroup", "UpdateReplacePolicy": "Retain", }, - "apigatewaysqsEncryptionKey4A698F7C": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsapigatewayrole2BA120D3", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "apigatewaysqsLambdaRestApiAccount8FA59342": Object { "DependsOn": Array [ "apigatewaysqsRestApi03BFD711", @@ -1180,21 +1015,6 @@ Object { "Properties": Object { "PolicyDocument": Object { "Statement": Array [ - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, - }, Object { "Action": "sqs:SendMessage", "Effect": "Allow", @@ -1239,23 +1059,13 @@ Object { }, "apigatewaysqsdeadLetterQueue25B510FA": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", }, "Type": "AWS::SQS::Queue", }, "apigatewaysqsqueueE186B895": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": Object { "deadLetterTargetArn": Object { "Fn::GetAtt": Array [ @@ -1308,76 +1118,6 @@ Object { "Type": "AWS::Logs::LogGroup", "UpdateReplacePolicy": "Retain", }, - "apigatewaysqsEncryptionKey4A698F7C": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsapigatewayrole2BA120D3", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "apigatewaysqsLambdaRestApiAccount8FA59342": Object { "DependsOn": Array [ "apigatewaysqsRestApi03BFD711", @@ -1647,21 +1387,6 @@ Object { "Properties": Object { "PolicyDocument": Object { "Statement": Array [ - Object { - "Action": Array [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*", - ], - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, - }, Object { "Action": "sqs:ReceiveMessage", "Effect": "Allow", @@ -1686,23 +1411,13 @@ Object { }, "apigatewaysqsdeadLetterQueue25B510FA": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", }, "Type": "AWS::SQS::Queue", }, "apigatewaysqsqueueE186B895": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "apigatewaysqsEncryptionKey4A698F7C", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": Object { "deadLetterTargetArn": Object { "Fn::GetAtt": Array [ diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/apigateway-sqs.test.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/apigateway-sqs.test.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/apigateway-sqs.test.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/apigateway-sqs.test.ts index 2fdbf63a3..c680a6fee 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/apigateway-sqs.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/apigateway-sqs.test.ts @@ -40,7 +40,6 @@ test('Test deployment w/ DLQ', () => { new ApiGatewayToSqs(stack, 'api-gateway-sqs', { apiGatewayProps: {}, queueProps: {}, - encryptionKeyProps: {}, createRequestTemplate: "{}", allowCreateOperation: true, allowReadOperation: true, @@ -61,7 +60,6 @@ test('Test deployment w/o DLQ', () => { new ApiGatewayToSqs(stack, 'api-gateway-sqs', { apiGatewayProps: {}, queueProps: {}, - encryptionKeyProps: {}, createRequestTemplate: "{}", allowCreateOperation: true, allowReadOperation: false, @@ -90,19 +88,20 @@ test('Test deployment w/o DLQ', () => { // -------------------------------------------------------------- // Test the getter methods // -------------------------------------------------------------- -test('Test the getter methods', () => { +test('Test properties', () => { // Stack const stack = new Stack(); // Helper declaration const pattern = new ApiGatewayToSqs(stack, 'api-gateway-sqs', { apiGatewayProps: {}, queueProps: {}, - encryptionKeyProps: {}, deployDeadLetterQueue: true, maxReceiveCount: 3 }); // Assertion 1 - expect(pattern.api()).toBeDefined(); + expect(pattern.apiGateway !== null); // Assertion 2 - expect(pattern.sqsQueue()).toBeDefined(); + expect(pattern.sqsQueue !== null); + // Assertion 3 + expect(pattern.apiGatewayRole !== null); }); diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json similarity index 84% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json index e8c175405..6f62f8470 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json @@ -1,96 +1,16 @@ { "Description": "Integration Test for aws-apigateway-sqs", "Resources": { - "testapigatewaysqsEncryptionKeyFD2F56B1": { - "Type": "AWS::KMS::Key", - "Properties": { - "KeyPolicy": { - "Statement": [ - { - "Action": [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - }, - { - "Action": [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "testapigatewaysqsapigatewayrole07110CD6", - "Arn" - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "EnableKeyRotation": true - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "testapigatewaysqsdeadLetterQueueAA4F6060": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testapigatewaysqsEncryptionKeyFD2F56B1", - "Arn" - ] - } + "KmsMasterKeyId": "alias/aws/sqs" } }, "testapigatewaysqsqueue8EDC3CAF": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testapigatewaysqsEncryptionKeyFD2F56B1", - "Arn" - ] - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": { "deadLetterTargetArn": { "Fn::GetAtt": [ @@ -546,21 +466,6 @@ "Properties": { "PolicyDocument": { "Statement": [ - { - "Action": [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*" - ], - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "testapigatewaysqsEncryptionKeyFD2F56B1", - "Arn" - ] - } - }, { "Action": "sqs:SendMessage", "Effect": "Allow", diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts index e913a8800..6b421148d 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.ts @@ -24,7 +24,6 @@ stack.templateOptions.description = 'Integration Test for aws-apigateway-sqs'; const props: ApiGatewayToSqsProps = { apiGatewayProps: {}, queueProps: {}, - encryptionKeyProps: {}, allowReadOperation: true, allowCreateOperation: true, allowDeleteOperation: true, diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.expected.json similarity index 78% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.expected.json index 92c44fedd..e91626529 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.expected.json @@ -1,96 +1,16 @@ { "Description": "Integration Test for aws-apigateway-sqs", "Resources": { - "testapigatewaysqsdefaultEncryptionKey76707C9E": { - "Type": "AWS::KMS::Key", - "Properties": { - "KeyPolicy": { - "Statement": [ - { - "Action": [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - }, - { - "Action": [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "testapigatewaysqsdefaultapigatewayrole080B85EC", - "Arn" - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "EnableKeyRotation": true - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "testapigatewaysqsdefaultdeadLetterQueue24467CAD": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testapigatewaysqsdefaultEncryptionKey76707C9E", - "Arn" - ] - } + "KmsMasterKeyId": "alias/aws/sqs" } }, "testapigatewaysqsdefaultqueueCAC098BE": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testapigatewaysqsdefaultEncryptionKey76707C9E", - "Arn" - ] - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": { "deadLetterTargetArn": { "Fn::GetAtt": [ @@ -377,21 +297,6 @@ "Properties": { "PolicyDocument": { "Statement": [ - { - "Action": [ - "kms:Decrypt", - "kms:Encrypt", - "kms:ReEncrypt*", - "kms:GenerateDataKey*" - ], - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "testapigatewaysqsdefaultEncryptionKey76707C9E", - "Arn" - ] - } - }, { "Action": "sqs:ReceiveMessage", "Effect": "Allow", diff --git a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.ts index 3da9f042d..4fd448640 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-apigateway-sqs/test/integ.no-arguments.ts +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.no-arguments.ts @@ -23,8 +23,7 @@ stack.templateOptions.description = 'Integration Test for aws-apigateway-sqs'; // Definitions const props: ApiGatewayToSqsProps = { apiGatewayProps: {}, - queueProps: {}, - encryptionKeyProps: {} + queueProps: {} }; new ApiGatewayToSqs(stack, 'test-api-gateway-sqs-default', props); diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md index 1901ce22b..ebfb0c006 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,22 +12,23 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-cloudfront-apigateway-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_cloudfront_apigateway_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_apigateway_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cloudfront-apigateway-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfrontapigatewaylambda`| -This AWS Solutions Konstruk implements an AWS Cloudfront fronting an Amazon API Gateway Lambda backed REST API. +This AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway Lambda backed REST API. Here is a minimal deployable pattern definition: ``` javascript -import * as defaults from '@aws-solutions-konstruk/core'; -import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda'; +import * as defaults from '@aws-solutions-constructs/core'; +import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda'; const stack = new Stack(); @@ -65,16 +64,34 @@ _Parameters_ |existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Existing instance of Lambda Function object| |lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|Optional user provided props to override the default props for Lambda function| |apiGatewayProps?|[`api.LambdaRestApiProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.LambdaRestApiProps.html)|Optional user provided props to override the default props for API Gateway| -|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for Cloudfront Distribution| -|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all resonses from cloudfront| +|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for CloudFront Distribution| +|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|cloudFrontWebDistribution()|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| -|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.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.| +|cloudFrontWebDistribution|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| +|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.| +|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.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon CloudFront +* Configure Access logging for CloudFront WebDistribution +* Enable automatic injection of best practice HTTP security headers in all responses from CloudFront WebDistribution + +### Amazon API Gateway +* Deploy a regional API endpoint +* Enable CloudWatch logging for API Gateway +* Configure least privilege access IAM role for API Gateway +* Set the default authorizationType for all API methods to IAM + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/lib/index.ts similarity index 68% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/lib/index.ts index fefc17799..76b74531c 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/lib/index.ts @@ -14,9 +14,9 @@ import * as api from '@aws-cdk/aws-apigateway'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cloudfront from '@aws-cdk/aws-cloudfront'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; -import { CloudFrontToApiGateway } from '@aws-solutions-konstruk/aws-cloudfront-apigateway'; +import { CloudFrontToApiGateway } from '@aws-solutions-constructs/aws-cloudfront-apigateway'; /** * @summary The properties for the CloudFrontToApiGatewayToLambda Construct @@ -57,7 +57,7 @@ export interface CloudFrontToApiGatewayToLambdaProps { readonly cloudFrontDistributionProps?: cloudfront.CloudFrontWebDistributionProps | any, /** * Optional user provided props to turn on/off the automatic injection of best practice HTTP - * security headers in all resonses from cloudfront + * security headers in all responses from cloudfront * * @default - true */ @@ -65,9 +65,9 @@ export interface CloudFrontToApiGatewayToLambdaProps { } export class CloudFrontToApiGatewayToLambda extends Construct { - private cloudfront: cloudfront.CloudFrontWebDistribution; - private api: api.RestApi; - private fn: lambda.Function; + public readonly cloudFrontWebDistribution: cloudfront.CloudFrontWebDistribution; + public readonly apiGateway: api.RestApi; + public readonly lambdaFunction: lambda.Function; /** * @summary Constructs a new instance of the CloudFrontToApiGatewayToLambda class. @@ -80,50 +80,20 @@ export class CloudFrontToApiGatewayToLambda extends Construct { constructor(scope: Construct, id: string, props: CloudFrontToApiGatewayToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); - this.api = defaults.RegionalLambdaRestApi(this, this.fn, props.apiGatewayProps); + this.apiGateway = defaults.RegionalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps); const apiCloudfront: CloudFrontToApiGateway = new CloudFrontToApiGateway(this, 'CloudFrontToApiGateway', { - existingApiGatewayObj: this.api, + existingApiGatewayObj: this.apiGateway, cloudFrontDistributionProps: props.cloudFrontDistributionProps, insertHttpSecurityHeaders: props.insertHttpSecurityHeaders }); - this.cloudfront = apiCloudfront.cloudFrontWebDistribution(); - } - - /** - * @summary Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct. - * @returns {cloudfront.CloudFrontWebDistribution} Instance of CloudFrontWebDistribution created by the construct - * @since 0.8.0 - * @access public - */ - public cloudFrontWebDistribution(): cloudfront.CloudFrontWebDistribution { - return this.cloudfront; - } - - /** - * @summary Returns an instance of api.RestApi created by the construct. - * @returns {api.RestApi} Instance of RestApi created by the construct - * @since 0.8.0 - * @access public - */ - public restApi(): api.RestApi { - return this.api; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; + this.cloudFrontWebDistribution = apiCloudfront.cloudFrontWebDistribution; } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/package.json similarity index 53% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/package.json index f75483ec6..6492dde58 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-cloudfront-apigateway-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS Cloudfront to AWS API Gateway to AWS Lambda integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,36 +34,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.cloudfrontapigatewaylambda", + "package": "software.amazon.awsconstructs.services.cloudfrontapigatewaylambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "cloudfrontapigatewaylambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.CloudfrontApiGatewayLambda", - "packageId": "Amazon.Konstruk.AWS.CloudfrontApiGatewayLambda", + "namespace": "Amazon.Constructs.AWS.CloudfrontApiGatewayLambda", + "packageId": "Amazon.Constructs.AWS.CloudfrontApiGatewayLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-cloudfront-apigateway-lambda", - "module": "aws_solutions_konstruk.aws_cloudfront_apigateway_lambda" + "distName": "aws-solutions-constructs.aws-cloudfront-apigateway-lambda", + "module": "aws_solutions_constructs.aws_cloudfront_apigateway_lambda" } } }, "dependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-solutions-konstruk/aws-cloudfront-apigateway": "~0.8.1", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-solutions-constructs/aws-cloudfront-apigateway": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,13 +73,13 @@ ] }, "peerDependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-solutions-konstruk/aws-cloudfront-apigateway": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-solutions-constructs/aws-cloudfront-apigateway": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap index b48deef2f..d8e5c4cfa 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/__snapshots__/test.cloudfront-apigateway-lambda.test.js.snap @@ -765,7 +765,7 @@ Object { Object { "Ref": "testcloudfrontapigatewaylambdaLambdaRestApi6A4CBD44", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -806,7 +806,7 @@ Object { Object { "Ref": "testcloudfrontapigatewaylambdaLambdaRestApiDeploymentStageprod4617A7B7", }, - "/*/{proxy+}", + "/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json index 28df3967d..305f776d3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.expected.json @@ -240,7 +240,7 @@ { "Ref": "testcloudfrontapigatewaylambdaLambdaRestApiDeploymentStageprod4617A7B7" }, - "/*/{proxy+}" + "/*/*" ] ] } @@ -277,7 +277,7 @@ { "Ref": "testcloudfrontapigatewaylambdaLambdaRestApi6A4CBD44" }, - "/test-invoke-stage/*/{proxy+}" + "/test-invoke-stage/*/*" ] ] } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/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 similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/test/test.cloudfront-apigateway-lambda.test.ts index c9185ae4d..c76368890 100644 --- a/source/patterns/@aws-solutions-konstruk/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 @@ -49,14 +49,14 @@ test('snapshot test CloudFrontToApiGatewayToLambda default params', () => { expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: CloudFrontToApiGatewayToLambda = deployNewFunc(stack); - expect(construct.cloudFrontWebDistribution()).toBeDefined(); - expect(construct.restApi()).toBeDefined(); - expect(construct.lambdaFunction()).toBeDefined(); + expect(construct.cloudFrontWebDistribution !== null); + expect(construct.apiGateway !== null); + expect(construct.lambdaFunction !== null); }); test('check lambda function properties for deploy: true', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.gitignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.npmignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md similarity index 61% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/README.md rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md index 82ae9d7f1..621f1fb6b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,22 +12,23 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-cloudfront-apigateway/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_cloudfront_apigateway`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-cloudfront-apigateway`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_apigateway`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cloudfront-apigateway`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfrontapigateway`| -This AWS Solutions Konstruk implements an AWS Cloudfront fronting an Amazon API Gateway REST API. +This AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway REST API. Here is a minimal deployable pattern definition: ``` javascript -const { defaults } = require('@aws-solutions-konstruk/core'); -const { CloudFrontToApiGateway } = require('@aws-solutions-konstruk/aws-cloudfront-apigateway'); +const { defaults } = require('@aws-solutions-constructs/core'); +const { CloudFrontToApiGateway } = require('@aws-solutions-constructs/aws-cloudfront-apigateway'); const stack = new Stack(); @@ -66,14 +65,25 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| |existingApiGatewayObj|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApi.html)|The regional API Gateway that will be fronted with the CloudFront| -|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps | any`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for Cloudfront Distribution| -|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all resonses from cloudfront| +|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps | any`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for CloudFront Distribution| +|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|cloudFrontWebDistribution()|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| -|restApi()|[`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.| +|cloudFrontWebDistribution|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| +|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.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon CloudFront +* Configure Access logging for CloudFront WebDistribution +* Enable automatic injection of best practice HTTP security headers in all responses from CloudFront WebDistribution + +### Amazon API Gateway +* User provided API Gateway object is used as-is ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/architecture.png b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/lib/index.ts similarity index 66% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/lib/index.ts index 06e7901ed..022f32822 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/lib/index.ts @@ -13,7 +13,7 @@ import * as api from '@aws-cdk/aws-apigateway'; import * as cloudfront from '@aws-cdk/aws-cloudfront'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -34,7 +34,7 @@ export interface CloudFrontToApiGatewayProps { readonly cloudFrontDistributionProps?: cloudfront.CloudFrontWebDistributionProps | any, /** * Optional user provided props to turn on/off the automatic injection of best practice HTTP - * security headers in all resonses from cloudfront + * security headers in all responses from cloudfront * * @default - true */ @@ -42,8 +42,8 @@ export interface CloudFrontToApiGatewayProps { } export class CloudFrontToApiGateway extends Construct { - private cloudfront: cloudfront.CloudFrontWebDistribution; - private api: api.RestApi; + public readonly cloudFrontWebDistribution: cloudfront.CloudFrontWebDistribution; + public readonly apiGateway: api.RestApi; /** * @summary Constructs a new instance of the CloudFrontToApiGateway class. @@ -56,29 +56,9 @@ export class CloudFrontToApiGateway extends Construct { constructor(scope: Construct, id: string, props: CloudFrontToApiGatewayProps) { super(scope, id); - this.api = props.existingApiGatewayObj; + this.apiGateway = props.existingApiGatewayObj; - this.cloudfront = defaults.CloudFrontDistributionForApiGateway(this, props.existingApiGatewayObj, + this.cloudFrontWebDistribution = defaults.CloudFrontDistributionForApiGateway(this, props.existingApiGatewayObj, props.cloudFrontDistributionProps, props.insertHttpSecurityHeaders); } - - /** - * @summary Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct. - * @returns {cloudfront.CloudFrontWebDistribution} Instance of CloudFrontWebDistribution created by the construct - * @since 0.8.0 - * @access public - */ - public cloudFrontWebDistribution(): cloudfront.CloudFrontWebDistribution { - return this.cloudfront; - } - - /** - * @summary Returns an instance of api.RestApi created by the construct. - * @returns {api.RestApi} Instance of RestApi created by the construct - * @since 0.8.0 - * @access public - */ - public restApi(): api.RestApi { - return this.api; - } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/package.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/package.json similarity index 56% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/package.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/package.json index 95cb9debf..3135dd4ca 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-cloudfront-apigateway", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-cloudfront-apigateway", + "version": "1.46.0", "description": "CDK Constructs for AWS Cloudfront to AWS API Gateway integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway" }, "author": { "name": "Amazon Web Services", @@ -34,35 +34,35 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.cloudfrontapigateway", + "package": "software.amazon.awsconstructs.services.cloudfrontapigateway", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "cloudfrontapigateway" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.CloudfrontApiGateway", - "packageId": "Amazon.Konstruk.AWS.CloudfrontApiGateway", + "namespace": "Amazon.Constructs.AWS.CloudfrontApiGateway", + "packageId": "Amazon.Constructs.AWS.CloudfrontApiGateway", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-cloudfront-apigateway", - "module": "aws_solutions_konstruk.aws_cloudfront_apigateway" + "distName": "aws-solutions-constructs.aws-cloudfront-apigateway", + "module": "aws_solutions_constructs.aws_cloudfront_apigateway" } } }, "dependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -72,12 +72,12 @@ ] }, "peerDependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap index a1739d0ba..a454b7a32 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/__snapshots__/test.cloudfront-apigateway.test.js.snap @@ -529,7 +529,7 @@ Object { Object { "Ref": "LambdaRestApiDeploymentStageprodB1F3862A", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -566,7 +566,7 @@ Object { Object { "Ref": "LambdaRestApi95870433", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json similarity index 99% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json index 1f4d0046f..a9577acc8 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.expected.json @@ -240,7 +240,7 @@ { "Ref": "LambdaRestApiDeploymentStageprodB1F3862A" }, - "/*/{proxy+}" + "/*/*" ] ] } @@ -277,7 +277,7 @@ { "Ref": "LambdaRestApi95870433" }, - "/test-invoke-stage/*/{proxy+}" + "/test-invoke-stage/*/*" ] ] } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.ts index d9dffb3cb..3da513c56 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/integ.no-arguments.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.no-arguments.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { CloudFrontToApiGateway } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // Setup const app = new App(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts index 15f8d4f6e..10f7c80b3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/test.cloudfront-apigateway.test.ts @@ -14,7 +14,7 @@ import { SynthUtils, ResourcePart } from '@aws-cdk/assert'; import { CloudFrontToApiGateway } from "../lib"; import * as cdk from "@aws-cdk/core"; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import * as lambda from '@aws-cdk/aws-lambda'; import '@aws-cdk/assert/jest'; @@ -45,8 +45,8 @@ test('check getter methods', () => { const construct: CloudFrontToApiGateway = deploy(stack); - expect(construct.cloudFrontWebDistribution()).toBeDefined(); - expect(construct.restApi()).toBeDefined(); + expect(construct.cloudFrontWebDistribution !== null); + expect(construct.apiGateway !== null); }); test('test cloudfront DomainName', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.gitignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.npmignore b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md similarity index 61% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/README.md rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md index 4a14b7186..23a682421 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-cloudfront-s3/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_cloudfront_s3`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-cloudfront-s3`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_s3`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cloudfront-s3`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfronts3`| -This AWS Solutions Konstruk implements an AWS Cloudfront fronting an AWS S3 Bucket. +This AWS Solutions Construct implements an AWS CloudFront fronting an AWS S3 Bucket. Here is a minimal deployable pattern definition: ``` javascript -const { CloudFrontToS3 } = require('@aws-solutions-konstruk/aws-cloudfront-s3'); +const { CloudFrontToS3 } = require('@aws-solutions-constructs/aws-cloudfront-s3'); new CloudFrontToS3(stack, 'test-cloudfront-s3', { deployBucket: true @@ -55,15 +54,30 @@ _Parameters_ |deployBucket|`boolean`|Whether to create a S3 Bucket or use an existing S3 Bucket| |existingBucketObj?|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Existing instance of S3 Bucket object| |bucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|Optional user provided props to override the default props for S3 Bucket| -|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for Cloudfront Distribution| -|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all resonses from cloudfront| +|cloudFrontDistributionProps?|[`cloudfront.CloudFrontWebDistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistributionProps.html)|Optional user provided props to override the default props for CloudFront Distribution| +|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|cloudFrontWebDistribution()|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| -|bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| +|cloudFrontWebDistribution|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon CloudFront +* Configure Access logging for CloudFront WebDistribution +* Enable automatic injection of best practice HTTP security headers in all responses from CloudFront WebDistribution + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/architecture.png b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts similarity index 73% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts index 1732e7f07..f702359c3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/lib/index.ts @@ -14,7 +14,7 @@ import * as cloudfront from '@aws-cdk/aws-cloudfront'; import * as s3 from '@aws-cdk/aws-s3'; import { Construct } from '@aws-cdk/core'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; /** * @summary The properties for the CloudFrontToS3 Construct @@ -49,7 +49,7 @@ export interface CloudFrontToS3Props { readonly cloudFrontDistributionProps?: cloudfront.CloudFrontWebDistributionProps | any, /** * Optional user provided props to turn on/off the automatic injection of best practice HTTP - * security headers in all resonses from cloudfront + * security headers in all responses from cloudfront * * @default - true */ @@ -57,8 +57,8 @@ export interface CloudFrontToS3Props { } export class CloudFrontToS3 extends Construct { - private cloudfront: cloudfront.CloudFrontWebDistribution; - private s3Bucket: s3.Bucket; + public readonly cloudFrontWebDistribution: cloudfront.CloudFrontWebDistribution; + public readonly s3Bucket: s3.Bucket; /** * @summary Constructs a new instance of the CloudFrontToS3 class. @@ -77,27 +77,7 @@ export class CloudFrontToS3 extends Construct { bucketProps: props.bucketProps }); - this.cloudfront = defaults.CloudFrontDistributionForS3(this, this.s3Bucket, + this.cloudFrontWebDistribution = defaults.CloudFrontDistributionForS3(this, this.s3Bucket, props.cloudFrontDistributionProps, props.insertHttpSecurityHeaders); } - - /** - * @summary Returns an instance of cloudfront.CloudFrontWebDistribution created by the construct - * @returns {cloudfront.CloudFrontWebDistribution} Instance of CloudFrontWebDistribution created by the construct - * @since 0.8.0 - * @access public - */ - public cloudFrontWebDistribution(): cloudfront.CloudFrontWebDistribution { - return this.cloudfront; - } - - /** - * @summary Returns an instance of s3.Bucket created by the construct. - * @returns {s3.Bucket} Instance of Bucket created by the construct - * @since 0.8.0 - * @access public - */ - public bucket(): s3.Bucket { - return this.s3Bucket; - } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/package.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/package.json similarity index 61% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/package.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/package.json index 943f0ab85..33a3b38e4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-cloudfront-s3", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-cloudfront-s3", + "version": "1.46.0", "description": "CDK Constructs for AWS Cloudfront to AWS S3 integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-cloudfront-s3" }, "author": { "name": "Amazon Web Services", @@ -34,33 +34,33 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.cloudfronts3", + "package": "software.amazon.awsconstructs.services.cloudfronts3", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "cloudfronts3" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.CloudfrontS3", - "packageId": "Amazon.Konstruk.AWS.CloudfrontS3", + "namespace": "Amazon.Constructs.AWS.CloudfrontS3", + "packageId": "Amazon.Constructs.AWS.CloudfrontS3", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-cloudfront-s3", - "module": "aws_solutions_konstruk.aws_cloudfront_s3" + "distName": "aws-solutions-constructs.aws-cloudfront-s3", + "module": "aws_solutions_constructs.aws_cloudfront_s3" } } }, "dependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -70,10 +70,10 @@ ] }, "peerDependencies": { - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/__snapshots__/test.cloudfront-s3.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/__snapshots__/test.cloudfront-s3.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/__snapshots__/test.cloudfront-s3.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/__snapshots__/test.cloudfront-s3.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-security-headers.expected.json b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-security-headers.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-security-headers.expected.json rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-security-headers.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-security-headers.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-security-headers.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/integ.no-security-headers.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/integ.no-security-headers.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts rename to source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts index 23098e514..63ae5c977 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts @@ -212,11 +212,11 @@ test('check exception for Missing existingObj from props for deploy = false', () } }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: CloudFrontToS3 = deploy(stack); - expect(construct.cloudFrontWebDistribution()).toBeDefined(); - expect(construct.bucket()).toBeDefined(); + expect(construct.cloudFrontWebDistribution !== null); + expect(construct.s3Bucket !== null); }); diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md similarity index 62% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md index 2b139ac10..62bb315c4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-cognito-apigateway-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_cognito_apigateway_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-cognito-apigateway-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cognito_apigateway_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-cognito-apigateway-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cognitoapigatewaylambda`| -This AWS Solutions Konstruk implements an Amazon Cognito securing an Amazon API Gateway Lambda backed REST APIs pattern. +This AWS Solutions Construct implements an Amazon Cognito securing an Amazon API Gateway Lambda backed REST APIs pattern. Here is a minimal deployable pattern definition: ``` javascript -const { CognitoToApiGatewayToLambda } = require('@aws-solutions-konstruk/aws-cognito-apigateway-lambda'); +const { CognitoToApiGatewayToLambda } = require('@aws-solutions-constructs/aws-cognito-apigateway-lambda'); const stack = new Stack(app, 'test-cognito-apigateway-lambda-stack'); @@ -71,10 +70,28 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|restApi()|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApi.html)|Returns an instance of api.RestApi created by the construct| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| -|userPool()|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| -|userPoolClient()|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| +|apiGateway|[`api.RestApi`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.RestApi.html)|Returns an instance of api.RestApi created by the construct| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|userPool|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| +|userPoolClient|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon Cognito +* Set password policy for User Pools +* Enforce the advanced security mode for User Pools + +### Amazon API Gateway +* Deploy an edge-optimized API endpoint +* Enable CloudWatch logging for API Gateway +* Configure least privilege access IAM role for API Gateway +* Set the default authorizationType for all API methods to IAM + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/lib/index.ts similarity index 66% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/lib/index.ts index 8e59fadaf..b10eb0334 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/lib/index.ts @@ -14,7 +14,7 @@ import * as api from '@aws-cdk/aws-apigateway'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cognito from '@aws-cdk/aws-cognito'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -63,10 +63,10 @@ export interface CognitoToApiGatewayToLambdaProps { } export class CognitoToApiGatewayToLambda extends Construct { - private userpool: cognito.UserPool; - private userpoolclient: cognito.UserPoolClient; - private api: api.RestApi; - private fn: lambda.Function; + public readonly userPool: cognito.UserPool; + public readonly userPoolClient: cognito.UserPoolClient; + public readonly apiGateway: api.RestApi; + public readonly lambdaFunction: lambda.Function; /** * @summary Constructs a new instance of the CognitoToApiGatewayToLambda class. @@ -79,24 +79,24 @@ export class CognitoToApiGatewayToLambda extends Construct { constructor(scope: Construct, id: string, props: CognitoToApiGatewayToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); - this.api = defaults.GlobalLambdaRestApi(this, this.fn, props.apiGatewayProps); - this.userpool = defaults.buildUserPool(this, props.cognitoUserPoolProps); - this.userpoolclient = defaults.buildUserPoolClient(this, this.userpool, props.cognitoUserPoolClientProps); + this.apiGateway = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps); + this.userPool = defaults.buildUserPool(this, props.cognitoUserPoolProps); + this.userPoolClient = defaults.buildUserPoolClient(this, this.userPool, props.cognitoUserPoolClientProps); const cfnAuthorizer = new api.CfnAuthorizer(this, 'CognitoAuthorizer', { - restApiId: this.api.restApiId, + restApiId: this.apiGateway.restApiId, type: 'COGNITO_USER_POOLS', - providerArns: [this.userpool.userPoolArn], + providerArns: [this.userPool.userPoolArn], identitySource: "method.request.header.Authorization", name: "authorizer" }); - this.api.methods.forEach((apiMethod) => { + this.apiGateway.methods.forEach((apiMethod) => { // Leave the authorizer NONE for HTTP OPTIONS method, for the rest set it to COGNITO const child = apiMethod.node.findChild('Resource') as api.CfnMethod; if (apiMethod.httpMethod === 'OPTIONS') { @@ -107,44 +107,4 @@ export class CognitoToApiGatewayToLambda extends Construct { } }); } - - /** - * @summary Returns an instance of api.RestApi created by the construct. - * @returns {api.RestApi} Instance of RestApi created by the construct - * @since 0.8.0 - * @access public - */ - public restApi(): api.RestApi { - return this.api; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of cognito.UserPool created by the construct. - * @returns {cognito.UserPool} Instance of UserPool created by the construct - * @since 0.8.0 - * @access public - */ - public userPool(): cognito.UserPool { - return this.userpool; - } - - /** - * @summary Returns an instance of cognito.UserPoolClient created by the construct. - * @returns {cognito.UserPoolClient} Instance of UserPoolClient created by the construct - * @since 0.8.0 - * @access public - */ - public userPoolClient(): cognito.UserPoolClient { - return this.userpoolclient; - } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/package.json similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/package.json index 0ea892116..b8ea4e4c7 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-cognito-apigateway-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-cognito-apigateway-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS Cognito to AWS API Gateway to AWS Lambda integration", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.cognitoapigatewaylambda", + "package": "software.amazon.awsconstructs.services.cognitoapigatewaylambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "cognitoapigatewaylambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.CognitoApigatewayLambda", - "packageId": "Amazon.Konstruk.AWS.CognitoApigatewayLambda", + "namespace": "Amazon.Constructs.AWS.CognitoApigatewayLambda", + "packageId": "Amazon.Constructs.AWS.CognitoApigatewayLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-cognito-apigateway-lambda", - "module": "aws_solutions_konstruk.aws_cognito_apigateway_lambda" + "distName": "aws-solutions-constructs.aws-cognito-apigateway-lambda", + "module": "aws_solutions_constructs.aws_cognito_apigateway_lambda" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap index 12f9d5f05..6a27c2a9b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/__snapshots__/test.cognito-apigateway-lambda.test.js.snap @@ -71,6 +71,24 @@ Object { }, "testcognitoapigatewaylambdaCognitoUserPoolClientDA118627": Object { "Properties": Object { + "AllowedOAuthFlows": Array [ + "implicit", + "code", + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": Array [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin", + ], + "CallbackURLs": Array [ + "https://example.com", + ], + "SupportedIdentityProviders": Array [ + "COGNITO", + ], "UserPoolId": Object { "Ref": "testcognitoapigatewaylambdaCognitoUserPoolD5E74489", }, @@ -79,6 +97,18 @@ Object { }, "testcognitoapigatewaylambdaCognitoUserPoolD5E74489": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, @@ -634,7 +664,7 @@ Object { Object { "Ref": "testcognitoapigatewaylambdaLambdaRestApi2E272431", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, @@ -675,7 +705,7 @@ Object { Object { "Ref": "testcognitoapigatewaylambdaLambdaRestApiDeploymentStageprod850C17D1", }, - "/*/{proxy+}", + "/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json index 3109add75..227901718 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/integ.no-arguments.expected.json @@ -239,7 +239,7 @@ { "Ref": "testcognitoapigatewaylambdaLambdaRestApiDeploymentStageprod850C17D1" }, - "/*/{proxy+}" + "/*/*" ] ] } @@ -276,7 +276,7 @@ { "Ref": "testcognitoapigatewaylambdaLambdaRestApi2E272431" }, - "/test-invoke-stage/*/{proxy+}" + "/test-invoke-stage/*/*" ] ] } @@ -584,6 +584,18 @@ "testcognitoapigatewaylambdaCognitoUserPoolD5E74489": { "Type": "AWS::Cognito::UserPool", "Properties": { + "AccountRecoverySetting": { + "RecoveryMechanisms": [ + { + "Name": "verified_phone_number", + "Priority": 1 + }, + { + "Name": "verified_email", + "Priority": 2 + } + ] + }, "AdminCreateUserConfig": { "AllowAdminCreateUserOnly": true }, @@ -615,7 +627,25 @@ "Properties": { "UserPoolId": { "Ref": "testcognitoapigatewaylambdaCognitoUserPoolD5E74489" - } + }, + "AllowedOAuthFlows": [ + "implicit", + "code" + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin" + ], + "CallbackURLs": [ + "https://example.com" + ], + "SupportedIdentityProviders": [ + "COGNITO" + ] } }, "testcognitoapigatewaylambdaCognitoAuthorizer170CACC9": { diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts index 2eefc1f17..07d2ff11f 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/test/test.cognito-apigateway-lambda.test.ts @@ -101,13 +101,13 @@ test('check exception for Missing existingObj from props for deploy = false', () } }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: CognitoToApiGatewayToLambda = deployNewFunc(stack); - expect(construct.userPool()).toBeDefined(); - expect(construct.userPoolClient()).toBeDefined(); - expect(construct.restApi()).toBeDefined(); - expect(construct.lambdaFunction()).toBeDefined(); + expect(construct.userPool !== null); + expect(construct.userPoolClient !== null); + expect(construct.apiGateway !== null); + expect(construct.lambdaFunction !== null); }); diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.gitignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.npmignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md similarity index 53% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md index 09da02fd5..6aebf0c15 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-dynamodb-stream-lambda-elasticsearch-kibana/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_dynamodb_stream_elasticsearch_kibana`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_dynamodb_stream_elasticsearch_kibana`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.dynamodbstreamlambdaelasticsearchkibana`| -This AWS Solutions Konstruk implements Amazon DynamoDB table with stream, AWS Lambda function and Amazon Elasticsearch Service with the least privileged permissions. +This AWS Solutions Construct implements Amazon DynamoDB table with stream, AWS Lambda function and Amazon Elasticsearch Service with the least privileged permissions. Here is a minimal deployable pattern definition: ``` javascript -const { DynamoDBStreamToLambdaToElasticSearchAndKibana, DynamoDBStreamToLambdaToElasticSearchAndKibanaProps } = require('@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana'); +const { DynamoDBStreamToLambdaToElasticSearchAndKibana, DynamoDBStreamToLambdaToElasticSearchAndKibanaProps } = require('@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana'); const props: DynamoDBStreamToLambdaToElasticSearchAndKibanaProps = { deployLambda: true, @@ -71,13 +70,38 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| -|userPool()|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| -|userPoolClient()|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| -|identityPool()|[`cognito.CfnIdentityPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnIdentityPool.html)|Returns an instance of cognito.CfnIdentityPool created by the construct| -|elasticsearchDomain()|[`elasticsearch.CfnDomain`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomain.html)|Returns an instance of elasticsearch.CfnDomain created by the construct| -|cloudwatchAlarms()|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| +|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| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|userPool|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| +|userPoolClient|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| +|identityPool|[`cognito.CfnIdentityPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnIdentityPool.html)|Returns an instance of cognito.CfnIdentityPool created by the construct| +|elasticsearchDomain|[`elasticsearch.CfnDomain`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomain.html)|Returns an instance of elasticsearch.CfnDomain created by the construct| +|cloudwatchAlarms|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon DynamoDB Table +* Set the billing mode for DynamoDB Table to On-Demand (Pay per request) +* Enable server-side encryption for DynamoDB Table using AWS managed KMS Key +* Creates a partition key called 'id' for DynamoDB Table +* Retain the Table when deleting the CloudFormation stack + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon Cognito +* Set password policy for User Pools +* Enforce the advanced security mode for User Pools + +### Amazon Elasticsearch Service +* Deploy best practices CloudWatch Alarms for the Elasticsearch Domain +* Secure the Kibana dashboard access with Cognito User Pools +* Enable server-side encryption for Elasticsearch Domain using AWS managed KMS Key +* Enable node-to-node encryption for Elasticsearch Domain +* Configure the cluster for the Amazon ES domain ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/architecture.png b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts similarity index 60% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts index 65fb464d0..746fc7584 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/lib/index.ts @@ -14,8 +14,8 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as elasticsearch from '@aws-cdk/aws-elasticsearch'; import { DynamoEventSourceProps } from '@aws-cdk/aws-lambda-event-sources'; -import { DynamoDBStreamToLambdaProps, DynamoDBStreamToLambda } from '@aws-solutions-konstruk/aws-dynamodb-stream-lambda'; -import { LambdaToElasticSearchAndKibanaProps, LambdaToElasticSearchAndKibana } from '@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana'; +import { DynamoDBStreamToLambdaProps, DynamoDBStreamToLambda } from '@aws-solutions-constructs/aws-dynamodb-stream-lambda'; +import { LambdaToElasticSearchAndKibanaProps, LambdaToElasticSearchAndKibana } from '@aws-solutions-constructs/aws-lambda-elasticsearch-kibana'; import * as dynamodb from '@aws-cdk/aws-dynamodb'; import * as cognito from '@aws-cdk/aws-cognito'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; @@ -75,7 +75,13 @@ export interface DynamoDBStreamToLambdaToElasticSearchAndKibanaProps { export class DynamoDBStreamToLambdaToElasticSearchAndKibana extends Construct { private dynamoDBStreamToLambda: DynamoDBStreamToLambda; private lambdaToElasticSearchAndKibana: LambdaToElasticSearchAndKibana; - private fn: lambda.Function; + public readonly lambdaFunction: lambda.Function; + public readonly dynamoTable: dynamodb.Table; + public readonly userPool: cognito.UserPool; + public readonly userPoolClient: cognito.UserPoolClient; + public readonly identityPool: cognito.CfnIdentityPool; + public readonly elasticsearchDomain: elasticsearch.CfnDomain; + public readonly cloudwatchAlarms: cloudwatch.Alarm[]; /** * @summary Constructs a new instance of the LambdaToDynamoDB class. @@ -98,85 +104,22 @@ export class DynamoDBStreamToLambdaToElasticSearchAndKibana extends Construct { this.dynamoDBStreamToLambda = new DynamoDBStreamToLambda(this, 'DynamoDBStreamToLambda', _props1); - this.fn = this.dynamoDBStreamToLambda.lambdaFunction(); + this.lambdaFunction = this.dynamoDBStreamToLambda.lambdaFunction; const _props2: LambdaToElasticSearchAndKibanaProps = { deployLambda: false, - existingLambdaObj: this.fn, + existingLambdaObj: this.lambdaFunction, domainName: props.domainName, esDomainProps: props.esDomainProps }; this.lambdaToElasticSearchAndKibana = new LambdaToElasticSearchAndKibana(this, 'LambdaToElasticSearch', _props2); - } - /** - * @summary Returns an instance of dynamodb.Table created by the construct. - * @returns {dynamodb.Table} Instance of dynamodb.Table created by the construct - * @since 0.8.0 - * @access public - */ - public dynamoTable(): dynamodb.Table { - return this.dynamoDBStreamToLambda.dynamoTable(); - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.dynamoDBStreamToLambda.lambdaFunction(); - } - - /** - * @summary Returns an instance of cognito.UserPool created by the construct. - * @returns {cognito.UserPool} Instance of UserPool created by the construct - * @since 0.8.0 - * @access public - */ - public userPool(): cognito.UserPool { - return this.lambdaToElasticSearchAndKibana.userPool(); - } - - /** - * @summary Returns an instance of cognito.UserPoolClient created by the construct. - * @returns {cognito.UserPoolClient} Instance of UserPoolClient created by the construct - * @since 0.8.0 - * @access public - */ - public userPoolClient(): cognito.UserPoolClient { - return this.lambdaToElasticSearchAndKibana.userPoolClient(); - } - - /** - * @summary Returns an instance of cognito.CfnIdentityPool created by the construct. - * @returns {cognito.CfnIdentityPool} Instance of CfnIdentityPool created by the construct - * @since 0.8.0 - * @access public - */ - public identityPool(): cognito.CfnIdentityPool { - return this.lambdaToElasticSearchAndKibana.identityPool(); - } - - /** - * @summary Returns an instance of elasticsearch.CfnDomain created by the construct. - * @returns {elasticsearch.CfnDomain} Instance of CfnDomain created by the construct - * @since 0.8.0 - * @access public - */ - public elasticsearchDomain(): elasticsearch.CfnDomain { - return this.lambdaToElasticSearchAndKibana.elasticsearchDomain(); - } - - /** - * @summary Returns a list of cloudwatch.Alarm created by the construct. - * @returns {cloudwatch.Alarm[]} List of cloudwatch.Alarm created by the construct - * @since 0.8.0 - * @access public - */ - public cloudwatchAlarms(): cloudwatch.Alarm[] { - return this.lambdaToElasticSearchAndKibana.cloudwatchAlarms(); + this.dynamoTable = this.dynamoDBStreamToLambda.dynamoTable; + this.userPool = this.lambdaToElasticSearchAndKibana.userPool; + this.userPoolClient = this.lambdaToElasticSearchAndKibana.userPoolClient; + this.identityPool = this.lambdaToElasticSearchAndKibana.identityPool; + this.elasticsearchDomain = this.lambdaToElasticSearchAndKibana.elasticsearchDomain; + this.cloudwatchAlarms = this.lambdaToElasticSearchAndKibana.cloudwatchAlarms; } } diff --git a/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json new file mode 100644 index 000000000..30f4645e7 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json @@ -0,0 +1,91 @@ +{ + "name": "@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana", + "version": "1.46.0", + "description": "CDK Constructs for Amazon Dynamodb stream to AWS Lambda to AWS Elasticsearch with Kibana integration", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana" + }, + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "scripts": { + "build": "tsc -b .", + "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", + "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", + "test": "jest --coverage", + "clean": "tsc -b --clean", + "watch": "tsc -b -w", + "integ": "cdk-integ", + "integ-no-clean": "cdk-integ --no-clean", + "integ-assert": "cdk-integ-assert", + "jsii": "jsii", + "jsii-pacmak": "jsii-pacmak", + "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", + "snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" + }, + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awsconstructs.services.dynamodbstreamlambdaelasticsearchkibana", + "maven": { + "groupId": "software.amazon.awsconstructs", + "artifactId": "dynamodbstreamlambdaelasticsearchkibana" + } + }, + "dotnet": { + "namespace": "Amazon.Constructs.AWS.DynamodbStreamLambdaElasticsearchKibana", + "packageId": "Amazon.Constructs.AWS.DynamodbStreamLambdaElasticsearchKibana", + "signAssembly": true, + "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" + }, + "python": { + "distName": "aws-solutions-constructs.aws-dynamodb-stream-lambda-elasticsearch-kibana", + "module": "aws_solutions_constructs.aws_dynamodb_stream_lambda_elasticsearch_kibana" + } + } + }, + "dependencies": { + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-dynamodb-stream-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-elasticsearch-kibana": "~1.46.0", + "constructs": "^3.0.2" + }, + "devDependencies": { + "@aws-cdk/assert": "~1.46.0", + "@types/jest": "^24.0.23", + "@types/node": "^10.3.0" + }, + "jest": { + "moduleFileExtensions": [ + "js" + ] + }, + "peerDependencies": { + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-dynamodb-stream-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-elasticsearch-kibana": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "constructs": "^3.0.2" + } +} diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap index 2679dfe89..15b4f5c9e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/__snapshots__/dynamodb-stream-lambda-elasticsearch-kibana.test.js.snap @@ -447,6 +447,24 @@ Object { }, "testdynamodbstreamlambdaelasticsearchstackLambdaToElasticSearchCognitoUserPoolClientE03C5E18": Object { "Properties": Object { + "AllowedOAuthFlows": Array [ + "implicit", + "code", + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": Array [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin", + ], + "CallbackURLs": Array [ + "https://example.com", + ], + "SupportedIdentityProviders": Array [ + "COGNITO", + ], "UserPoolId": Object { "Ref": "testdynamodbstreamlambdaelasticsearchstackLambdaToElasticSearchCognitoUserPoolF99F93E5", }, @@ -455,6 +473,18 @@ Object { }, "testdynamodbstreamlambdaelasticsearchstackLambdaToElasticSearchCognitoUserPoolF99F93E5": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts similarity index 78% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts index 62648749a..f62b089bd 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/dynamodb-stream-lambda-elasticsearch-kibana.test.ts @@ -14,10 +14,7 @@ import { SynthUtils } from '@aws-cdk/assert'; import { DynamoDBStreamToLambdaToElasticSearchAndKibana, DynamoDBStreamToLambdaToElasticSearchAndKibanaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as dynamodb from '@aws-cdk/aws-dynamodb'; import * as cdk from "@aws-cdk/core"; -import { CfnDomain } from '@aws-cdk/aws-elasticsearch'; -import { CfnIdentityPool, UserPool, UserPoolClient } from '@aws-cdk/aws-cognito'; import '@aws-cdk/assert/jest'; function deployNewFunc(stack: cdk.Stack) { @@ -58,18 +55,18 @@ test('check domain names', () => { }); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: DynamoDBStreamToLambdaToElasticSearchAndKibana = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.dynamoTable()).toBeInstanceOf(dynamodb.Table); - expect(construct.elasticsearchDomain()).toBeInstanceOf(CfnDomain); - expect(construct.identityPool()).toBeInstanceOf(CfnIdentityPool); - expect(construct.userPool()).toBeInstanceOf(UserPool); - expect(construct.userPoolClient()).toBeInstanceOf(UserPoolClient); - expect(construct.cloudwatchAlarms()).toHaveLength(9); + expect(construct.lambdaFunction !== null); + expect(construct.dynamoTable !== null); + expect(construct.elasticsearchDomain !== null); + expect(construct.identityPool !== null); + expect(construct.userPool !== null); + expect(construct.userPoolClient !== null); + expect(construct.cloudwatchAlarms !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json index 92458221c..e6bf88332 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json @@ -267,6 +267,18 @@ "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchCognitoUserPool77221A72": { "Type": "AWS::Cognito::UserPool", "Properties": { + "AccountRecoverySetting": { + "RecoveryMechanisms": [ + { + "Name": "verified_phone_number", + "Priority": 1 + }, + { + "Name": "verified_email", + "Priority": 2 + } + ] + }, "AdminCreateUserConfig": { "AllowAdminCreateUserOnly": true }, @@ -298,7 +310,25 @@ "Properties": { "UserPoolId": { "Ref": "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchCognitoUserPool77221A72" - } + }, + "AllowedOAuthFlows": [ + "implicit", + "code" + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin" + ], + "CallbackURLs": [ + "https://example.com" + ], + "SupportedIdentityProviders": [ + "COGNITO" + ] } }, "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchCognitoIdentityPool7F08EC45": { @@ -324,7 +354,7 @@ "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchUserPoolDomain0A904A18": { "Type": "AWS::Cognito::UserPoolDomain", "Properties": { - "Domain": "myvesperdomain", + "Domain": "myconstructsdomain1", "UserPoolId": { "Ref": "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchCognitoUserPool77221A72" } @@ -377,7 +407,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/myvesperdomain/*" + ":domain/myconstructsdomain1/*" ] ] } @@ -482,7 +512,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/myvesperdomain" + ":domain/myconstructsdomain1" ] ] } @@ -550,7 +580,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/myvesperdomain/*" + ":domain/myconstructsdomain1/*" ] ] } @@ -573,7 +603,7 @@ "Ref": "testdynamodbstreamlambdaelasticsearchkibanaLambdaToElasticSearchCognitoUserPool77221A72" } }, - "DomainName": "myvesperdomain", + "DomainName": "myconstructsdomain1", "EBSOptions": { "EBSEnabled": true, "VolumeSize": 10 diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts index d34bf0dce..092feacf3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/integ.no-arguments.ts @@ -27,7 +27,7 @@ const props: DynamoDBStreamToLambdaToElasticSearchAndKibanaProps = { runtime: lambda.Runtime.NODEJS_12_X, handler: 'index.handler' }, - domainName: 'myvesperdomain' + domainName: 'myconstructsdomain1' }; new DynamoDBStreamToLambdaToElasticSearchAndKibana(stack, 'test-dynamodb-stream-lambda-elasticsearch-kibana', props); diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md similarity index 65% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md index d7bf6887a..cf68afa76 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-dynamodb-stream-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_dynamodb_stream_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-dynamodb-stream-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_dynamodb_stream_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-dynamodb-stream-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.dynamodbstreamlambda`| -This AWS Solutions Konstruk implements a pattern Amazon DynamoDB table with stream to invoke the AWS Lambda function with the least privileged permissions. +This AWS Solutions Construct implements a pattern Amazon DynamoDB table with stream to invoke the AWS Lambda function with the least privileged permissions. Here is a minimal deployable pattern definition: ``` javascript -const { DynamoDBStreamToLambdaProps, DynamoDBStreamToLambda} = require('@aws-solutions-konstruk/aws-dynamodb-stream-lambda'); +const { DynamoDBStreamToLambdaProps, DynamoDBStreamToLambda} = require('@aws-solutions-constructs/aws-dynamodb-stream-lambda'); const props: DynamoDBStreamToLambdaProps = { deployLambda: true, @@ -69,8 +68,22 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|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| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon DynamoDB Table +* Set the billing mode for DynamoDB Table to On-Demand (Pay per request) +* Enable server-side encryption for DynamoDB Table using AWS managed KMS Key +* Creates a partition key called 'id' for DynamoDB Table +* Retain the Table when deleting the CloudFormation stack + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/lib/index.ts similarity index 73% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/lib/index.ts index 1d5edf5f8..3cef2c808 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/lib/index.ts @@ -14,9 +14,9 @@ import * as lambda from '@aws-cdk/aws-lambda'; import { DynamoEventSourceProps, DynamoEventSource } from '@aws-cdk/aws-lambda-event-sources'; import * as dynamodb from '@aws-cdk/aws-dynamodb'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; /** * @summary The properties for the DynamoDBStreamToLambda Construct @@ -58,8 +58,8 @@ export interface DynamoDBStreamToLambdaProps { } export class DynamoDBStreamToLambda extends Construct { - private fn: lambda.Function; - private table: dynamodb.Table; + public readonly lambdaFunction: lambda.Function; + public readonly dynamoTable: dynamodb.Table; /** * @summary Constructs a new instance of the LambdaToDynamoDB class. @@ -72,7 +72,7 @@ export class DynamoDBStreamToLambda extends Construct { constructor(scope: Construct, id: string, props: DynamoDBStreamToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -81,37 +81,16 @@ export class DynamoDBStreamToLambda extends Construct { // Set the default props for DynamoDB table if (props.dynamoTableProps) { const dynamoTableProps = overrideProps(defaults.DefaultTableWithStreamProps, props.dynamoTableProps); - this.table = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); } else { - this.table = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableWithStreamProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableWithStreamProps); } // Grant DynamoDB Stream read perimssion for lambda function - this.table.grantStreamRead(this.fn.grantPrincipal); + this.dynamoTable.grantStreamRead(this.lambdaFunction.grantPrincipal); // Create DynamDB trigger to invoke lambda function - this.fn.addEventSource(new DynamoEventSource(this.table, + this.lambdaFunction.addEventSource(new DynamoEventSource(this.dynamoTable, defaults.DynamoEventSourceProps(props.dynamoEventSourceProps))); } - - /** - * @summary Returns an instance of dynamodb.Table created by the construct. - * @returns {dynamodb.Table} Instance of dynamodb.Table created by the construct - * @since 0.8.0 - * @access public - */ - public dynamoTable(): dynamodb.Table { - return this.table; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/package.json similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/package.json index 03b23db00..3da3750b6 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-dynamodb-stream-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-dynamodb-stream-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS DynamoDB Stream to AWS Lambda integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.dynamodbstreamlambda", + "package": "software.amazon.awsconstructs.services.dynamodbstreamlambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "dynamodbstreamlambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.DynamodbStreamLambda", - "packageId": "Amazon.Konstruk.AWS.DynamodbStreamLambda", + "namespace": "Amazon.Constructs.AWS.DynamodbStreamLambda", + "packageId": "Amazon.Constructs.AWS.DynamodbStreamLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-dynamodb-stream-lambda", - "module": "aws_solutions_konstruk.aws_dynamodb_stream_lambda" + "distName": "aws-solutions-constructs.aws-dynamodb-stream-lambda", + "module": "aws_solutions_constructs.aws_dynamodb_stream_lambda" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/__snapshots__/dynamodb-stream-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/__snapshots__/dynamodb-stream-lambda.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/__snapshots__/dynamodb-stream-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/__snapshots__/dynamodb-stream-lambda.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts index 882057a33..22f4de34b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts @@ -187,8 +187,8 @@ test('check getter methods', () => { const construct: DynamoDBStreamToLambda = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.dynamoTable()).toBeInstanceOf(dynamodb.Table); + expect(construct.lambdaFunction !== null); + expect(construct.dynamoTable !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md similarity index 67% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md index 2d021809e..b0cf32b2e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-events-rule-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_events_rule_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-events-rule-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_events_rule_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-events-rule-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.eventsrulelambda`| -This AWS Solutions Konstruk implements an AWS Events rule and an AWS Lambda function. +This AWS Solutions Construct implements an AWS Events rule and an AWS Lambda function. Here is a minimal deployable pattern definition: ``` javascript -const { EventsRuleToLambdaProps, EventsRuleToLambda } = require('@aws-solutions-konstruk/aws-events-rule-lambda'); +const { EventsRuleToLambdaProps, EventsRuleToLambda } = require('@aws-solutions-constructs/aws-events-rule-lambda'); const props: EventsRuleToLambdaProps = { deployLambda: true, @@ -70,8 +69,19 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|eventsRule()|[`events.Rule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)|Returns an instance of events.Rule created by the construct| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|eventsRule|[`events.Rule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)|Returns an instance of events.Rule created by the construct| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon CloudWatch Events Rule +* Grant least privilege permissions to CloudWatch Events to trigger the Lambda Function + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/lib/index.ts similarity index 73% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/lib/index.ts index 4aa0fb7e0..830f25065 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/lib/index.ts @@ -13,10 +13,10 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as events from '@aws-cdk/aws-events'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import * as iam from '@aws-cdk/aws-iam'; import { Construct } from '@aws-cdk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; /** * @summary The properties for the CloudFrontToApiGateway Construct @@ -52,8 +52,8 @@ export interface EventsRuleToLambdaProps { } export class EventsRuleToLambda extends Construct { - private fn: lambda.Function; - private rule: events.Rule; + public readonly lambdaFunction: lambda.Function; + public readonly eventsRule: events.Rule; /** * @summary Constructs a new instance of the EventsRuleToLambda class. @@ -66,7 +66,7 @@ export class EventsRuleToLambda extends Construct { constructor(scope: Construct, id: string, props: EventsRuleToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -75,38 +75,18 @@ export class EventsRuleToLambda extends Construct { const lambdaFunc: events.IRuleTarget = { bind: () => ({ id: '', - arn: this.fn.functionArn + arn: this.lambdaFunction.functionArn }) }; const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([lambdaFunc]); const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true); - this.rule = new events.Rule(this, 'EventsRule', eventsRuleProps); + this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps); - this.fn.addPermission("LambdaInvokePermission", { + this.lambdaFunction.addPermission("LambdaInvokePermission", { principal: new iam.ServicePrincipal('events.amazonaws.com'), - sourceArn: this.rule.ruleArn + sourceArn: this.eventsRule.ruleArn }); } - - /** - * @summary Returns an instance of events.Rule created by the construct. - * @returns {events.Rule} Instance of events.Rule created by the construct - * @since 0.8.0 - * @access public - */ - public eventsRule(): events.Rule { - return this.rule; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/package.json similarity index 59% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/package.json index d554b93c5..e074d4c7d 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-events-rule-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-events-rule-lambda", + "version": "1.46.0", "description": "CDK Constructs for deploying AWS Events Rule that inveokes AWS Lambda", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-events-rule-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.eventsrulelambda", + "package": "software.amazon.awsconstructs.services.eventsrulelambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "eventsrulelambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.EventsRuleLambda", - "packageId": "Amazon.Konstruk.AWS.EventsRuleLambda", + "namespace": "Amazon.Constructs.AWS.EventsRuleLambda", + "packageId": "Amazon.Constructs.AWS.EventsRuleLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-events-rule-lambda", - "module": "aws_solutions_konstruk.aws_events_rule_lambda" + "distName": "aws-solutions-constructs.aws-events-rule-lambda", + "module": "aws_solutions_constructs.aws_events_rule_lambda" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-events": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-events": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/__snapshots__/events-rule-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/__snapshots__/events-rule-lambda.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/__snapshots__/events-rule-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/__snapshots__/events-rule-lambda.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/events-rule-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/events-rule-lambda.test.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/events-rule-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/events-rule-lambda.test.ts index ccfc1b548..e841d655b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/events-rule-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/events-rule-lambda.test.ts @@ -162,13 +162,13 @@ test('check events rule properties for deploy: true', () => { }); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: EventsRuleToLambda = deployNewFunc(stack); - expect(construct.eventsRule()).toBeInstanceOf(events.Rule); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); + expect(construct.eventsRule !== null); + expect(construct.lambdaFunction !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/integ.events-rule-no-argument.expected.json b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/integ.events-rule-no-argument.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/integ.events-rule-no-argument.expected.json rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/integ.events-rule-no-argument.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/integ.events-rule-no-argument.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/integ.events-rule-no-argument.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/integ.events-rule-no-argument.ts rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/integ.events-rule-no-argument.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-events-rule-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.gitignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.npmignore b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/.npmignore diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/README.md new file mode 100644 index 000000000..2af36fa18 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/README.md @@ -0,0 +1,88 @@ +# aws-events-rule-step-function module + + +--- + +![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) + +> All classes are under active development and subject to non-backward compatible changes or removal in any +> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. +> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. + +--- + + +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| +|:-------------|:-------------| +
+ +| **Language** | **Package** | +|:-------------|-----------------| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_events_rule_step_function`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-events-rule-step-function`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.eventsrulestepfunction`| + +This AWS Solutions Construct implements an AWS Events rule and an AWS Step function. + +Here is a minimal deployable pattern definition: + +``` javascript +const { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } = require('@aws-solutions-constructs/aws-events-rule-step-function'); + +const startState = new stepfunctions.Pass(stack, 'StartState'); + +const props: EventsRuleToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } +}; + +new EventsRuleToStepFunction(stack, 'test-events-rule-step-function-stack', props); +``` + +## Initializer + +``` text +new EventsRuleToStepFunction(scope: Construct, id: string, props: EventsRuleToStepFunctionProps); +``` + +_Parameters_ + +* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) +* id `string` +* props [`EventsRuleToStepFunctionProps`](#pattern-construct-props) + +## Pattern Construct Props + +| **Name** | **Type** | **Description** | +|:-------------|:----------------|-----------------| +|stateMachineProps|[`sfn.StateMachineProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachineProps.html)|Optional user provided props to override the default props for sfn.StateMachine| +|eventRuleProps|[`events.RuleProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)|User provided eventRuleProps to override the defaults| + +## Pattern Properties + +| **Name** | **Type** | **Description** | +|:-------------|:----------------|-----------------| +|eventsRule|[`events.Rule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)|Returns an instance of events.Rule created by the construct| +|stateMachine|[`sfn.StateMachine`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachine.html)|Returns an instance of sfn.StateMachine created by the construct| +|cloudwatchAlarms|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon CloudWatch Events Rule +* Grant least privilege permissions to CloudWatch Events to trigger the Lambda Function + +### AWS Step Function +* Enable CloudWatch logging for API Gateway +* Deploy best practices CloudWatch Alarms for the Step Function + +## Architecture +![Architecture Diagram](architecture.png) + +*** +© Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/architecture.png b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/architecture.png new file mode 100644 index 000000000..b71445842 Binary files /dev/null and b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/architecture.png differ diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/lib/index.ts new file mode 100644 index 000000000..4c783f4ae --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/lib/index.ts @@ -0,0 +1,84 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as events from '@aws-cdk/aws-events'; +import * as defaults from '@aws-solutions-constructs/core'; +import * as iam from '@aws-cdk/aws-iam'; +import { Construct } from '@aws-cdk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; + +/** + * @summary The properties for the EventsRuleToStepFunction Construct + */ +export interface EventsRuleToStepFunctionProps { + /** + * User provided StateMachineProps to override the defaults + * + * @default - None + */ + readonly stateMachineProps: sfn.StateMachineProps, + /** + * User provided eventRuleProps to override the defaults + * + * @default - None + */ + readonly eventRuleProps: events.RuleProps +} + +export class EventsRuleToStepFunction extends Construct { + public readonly stateMachine: sfn.StateMachine; + public readonly eventsRule: events.Rule; + public readonly cloudwatchAlarms: cloudwatch.Alarm[]; + + /** + * @summary Constructs a new instance of the EventsRuleToStepFunction class. + * @param {cdk.App} scope - represents the scope for all the resources. + * @param {string} id - this is a a scope-unique id. + * @param {EventsRuleToStepFunctionProps} props - user provided props for the construct + * @since 0.9.0 + * @access public + */ + constructor(scope: Construct, id: string, props: EventsRuleToStepFunctionProps) { + super(scope, id); + + this.stateMachine = defaults.buildStateMachine(this, props.stateMachineProps); + + // Create an IAM role for Events to start the State Machine + const eventsRole = new iam.Role(this, 'EventsRuleRole', { + assumedBy: new iam.ServicePrincipal('events.amazonaws.com') + }); + + // Grant the start execution permission to the Events service + this.stateMachine.grantStartExecution(eventsRole); + + // Setup the Events target + const stateMachine: events.IRuleTarget = { + bind: () => ({ + id: '', + arn: this.stateMachine.stateMachineArn, + role: eventsRole + }) + }; + + // Defaults props for the Events + const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([stateMachine]); + // Override the defaults with the user provided props + const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true); + // Create the Events Rule for the State Machine + this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps); + // Deploy best practices CW Alarms for State Machine + this.cloudwatchAlarms = defaults.buildStepFunctionCWAlarms(this, this.stateMachine); + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/package.json b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/package.json new file mode 100644 index 000000000..0b0df1563 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/package.json @@ -0,0 +1,87 @@ +{ + "name": "@aws-solutions-constructs/aws-events-rule-step-function", + "version": "1.46.0", + "description": "CDK Constructs for deploying AWS Events Rule that invokes AWS Step Function", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-events-rule-step-function" + }, + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "scripts": { + "build": "tsc -b .", + "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", + "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", + "test": "jest --coverage", + "clean": "tsc -b --clean", + "watch": "tsc -b -w", + "integ": "cdk-integ", + "integ-no-clean": "cdk-integ --no-clean", + "integ-assert": "cdk-integ-assert", + "jsii": "jsii", + "jsii-pacmak": "jsii-pacmak", + "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", + "snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" + }, + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awsconstructs.services.eventsrulestepfunction", + "maven": { + "groupId": "software.amazon.awsconstructs", + "artifactId": "eventsrulestepfunction" + } + }, + "dotnet": { + "namespace": "Amazon.Constructs.AWS.EventsRuleStepFunction", + "packageId": "Amazon.Constructs.AWS.EventsRuleStepFunction", + "signAssembly": true, + "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" + }, + "python": { + "distName": "aws-solutions-constructs.aws-events-rule-step-function", + "module": "aws_solutions_constructs.aws_events_rule_step_function" + } + } + }, + "dependencies": { + "@aws-cdk/aws-stepfunctions": "~1.46.0", + "@aws-cdk/aws-stepfunctions-tasks": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "constructs": "^3.0.2" + }, + "devDependencies": { + "@aws-cdk/assert": "~1.46.0", + "@types/jest": "^24.0.23", + "@types/node": "^10.3.0" + }, + "jest": { + "moduleFileExtensions": [ + "js" + ] + }, + "peerDependencies": { + "@aws-cdk/aws-stepfunctions": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "constructs": "^3.0.2", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-cdk/aws-stepfunctions-tasks": "~1.46.0" + } +} diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/__snapshots__/events-rule-step-function.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/__snapshots__/events-rule-step-function.test.js.snap new file mode 100644 index 000000000..f5b246db5 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/__snapshots__/events-rule-step-function.test.js.snap @@ -0,0 +1,257 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot test EventsRuleToStepFunction default params 1`] = ` +Object { + "Resources": Object { + "testeventsrulestepfunctionEventsRuleCC6E98C1": Object { + "Properties": Object { + "ScheduleExpression": "rate(5 minutes)", + "State": "ENABLED", + "Targets": Array [ + Object { + "Arn": Object { + "Ref": "testeventsrulestepfunctionStateMachineBB26627E", + }, + "Id": "Target0", + "RoleArn": Object { + "Fn::GetAtt": Array [ + "testeventsrulestepfunctionEventsRuleRole5AC0B2DC", + "Arn", + ], + }, + }, + ], + }, + "Type": "AWS::Events::Rule", + }, + "testeventsrulestepfunctionEventsRuleRole5AC0B2DC": Object { + "Properties": Object { + "AssumeRolePolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": Object { + "Service": "events.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "testeventsrulestepfunctionEventsRuleRoleDefaultPolicyA944B4E8": Object { + "Properties": Object { + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": Object { + "Ref": "testeventsrulestepfunctionStateMachineBB26627E", + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "testeventsrulestepfunctionEventsRuleRoleDefaultPolicyA944B4E8", + "Roles": Array [ + Object { + "Ref": "testeventsrulestepfunctionEventsRuleRole5AC0B2DC", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "testeventsrulestepfunctionExecutionAbortedAlarmD8769425": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that aborted exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "testeventsrulestepfunctionStateMachineBB26627E", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionsAborted", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Maximum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "testeventsrulestepfunctionExecutionFailedAlarmEFD0D099": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that failed exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "testeventsrulestepfunctionStateMachineBB26627E", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionsFailed", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "testeventsrulestepfunctionExecutionThrottledAlarm87D39B14": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that throttled exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "testeventsrulestepfunctionStateMachineBB26627E", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionThrottled", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "testeventsrulestepfunctionStateMachineBB26627E": Object { + "DependsOn": Array [ + "testeventsrulestepfunctionStateMachineRoleDefaultPolicy782F9F1D", + "testeventsrulestepfunctionStateMachineRole1488CE0E", + ], + "Properties": Object { + "DefinitionString": "{\\"StartAt\\":\\"StartState\\",\\"States\\":{\\"StartState\\":{\\"Type\\":\\"Pass\\",\\"End\\":true}}}", + "LoggingConfiguration": Object { + "Destinations": Array [ + Object { + "CloudWatchLogsLogGroup": Object { + "LogGroupArn": Object { + "Fn::GetAtt": Array [ + "testeventsrulestepfunctionStateMachineLogGroup3D62D3BF", + "Arn", + ], + }, + }, + }, + ], + "Level": "ERROR", + }, + "RoleArn": Object { + "Fn::GetAtt": Array [ + "testeventsrulestepfunctionStateMachineRole1488CE0E", + "Arn", + ], + }, + }, + "Type": "AWS::StepFunctions::StateMachine", + }, + "testeventsrulestepfunctionStateMachineLogGroup3D62D3BF": Object { + "DeletionPolicy": "Retain", + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + }, + "testeventsrulestepfunctionStateMachineRole1488CE0E": Object { + "Properties": Object { + "AssumeRolePolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": Object { + "Service": Object { + "Fn::Join": Array [ + "", + Array [ + "states.", + Object { + "Ref": "AWS::Region", + }, + ".amazonaws.com", + ], + ], + }, + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "testeventsrulestepfunctionStateMachineRoleDefaultPolicy782F9F1D": Object { + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations", + }, + ], + }, + }, + "Properties": Object { + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": Array [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + ], + "Effect": "Allow", + "Resource": "*", + }, + Object { + "Action": Array [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups", + ], + "Effect": "Allow", + "Resource": Object { + "Fn::Join": Array [ + "", + Array [ + "arn:aws:logs:", + Object { + "Ref": "AWS::Region", + }, + ":", + Object { + "Ref": "AWS::AccountId", + }, + ":*", + ], + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "testeventsrulestepfunctionStateMachineRoleDefaultPolicy782F9F1D", + "Roles": Array [ + Object { + "Ref": "testeventsrulestepfunctionStateMachineRole1488CE0E", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + }, +} +`; diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/events-rule-step-function.test.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/events-rule-step-function.test.ts new file mode 100644 index 000000000..c494edfb3 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/events-rule-step-function.test.ts @@ -0,0 +1,98 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import { SynthUtils } from '@aws-cdk/assert'; +import * as events from '@aws-cdk/aws-events'; +import { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } from '../lib/index'; +import { Duration } from '@aws-cdk/core'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import '@aws-cdk/assert/jest'; +import * as cdk from '@aws-cdk/core'; + +function deployNewStateMachine(stack: cdk.Stack) { + + const startState = new sfn.Pass(stack, 'StartState'); + + const props: EventsRuleToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } + }; + + return new EventsRuleToStepFunction(stack, 'test-events-rule-step-function', props); +} + +test('snapshot test EventsRuleToStepFunction default params', () => { + const stack = new cdk.Stack(); + deployNewStateMachine(stack); + expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); +}); + +test('check events rule role policy permissions', () => { + const stack = new cdk.Stack(); + + deployNewStateMachine(stack); + + expect(stack).toHaveResource("AWS::IAM::Policy", { + PolicyDocument: { + Statement: [ + { + Action: "states:StartExecution", + Effect: "Allow", + Resource: { + Ref: "testeventsrulestepfunctionStateMachineBB26627E" + } + } + ], + Version: "2012-10-17" + } + }); +}); + +test('check events rule properties', () => { + const stack = new cdk.Stack(); + + deployNewStateMachine(stack); + + expect(stack).toHaveResource('AWS::Events::Rule', { + ScheduleExpression: "rate(5 minutes)", + State: "ENABLED", + Targets: [ + { + Arn: { + Ref: "testeventsrulestepfunctionStateMachineBB26627E" + }, + Id: "Target0", + RoleArn: { + "Fn::GetAtt": [ + "testeventsrulestepfunctionEventsRuleRole5AC0B2DC", + "Arn" + ] + } + } + ] + }); +}); + +test('check properties', () => { + const stack = new cdk.Stack(); + + const construct: EventsRuleToStepFunction = deployNewStateMachine(stack); + + expect(construct.cloudwatchAlarms !== null); + expect(construct.stateMachine !== null); + expect(construct.eventsRule !== null); +}); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.expected.json b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.expected.json new file mode 100644 index 000000000..5708e457d --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.expected.json @@ -0,0 +1,253 @@ +{ + "Resources": { + "testeventsrulestepfunctionstackStateMachineLogGroupC3B398D4": { + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "testeventsrulestepfunctionstackStateMachineRoleA5C98F35": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "testeventsrulestepfunctionstackStateMachineRoleDefaultPolicyC51897AF": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries" + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "testeventsrulestepfunctionstackStateMachineRoleDefaultPolicyC51897AF", + "Roles": [ + { + "Ref": "testeventsrulestepfunctionstackStateMachineRoleA5C98F35" + } + ] + }, + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations" + } + ] + } + } + }, + "testeventsrulestepfunctionstackStateMachine48534048": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": "{\"StartAt\":\"StartState\",\"States\":{\"StartState\":{\"Type\":\"Pass\",\"End\":true}}}", + "RoleArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionstackStateMachineRoleA5C98F35", + "Arn" + ] + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionstackStateMachineLogGroupC3B398D4", + "Arn" + ] + } + } + } + ], + "Level": "ERROR" + } + }, + "DependsOn": [ + "testeventsrulestepfunctionstackStateMachineRoleDefaultPolicyC51897AF", + "testeventsrulestepfunctionstackStateMachineRoleA5C98F35" + ] + }, + "testeventsrulestepfunctionstackEventsRuleRole6AD4C16A": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "testeventsrulestepfunctionstackEventsRuleRoleDefaultPolicy9F3CC359": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "testeventsrulestepfunctionstackStateMachine48534048" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "testeventsrulestepfunctionstackEventsRuleRoleDefaultPolicy9F3CC359", + "Roles": [ + { + "Ref": "testeventsrulestepfunctionstackEventsRuleRole6AD4C16A" + } + ] + } + }, + "testeventsrulestepfunctionstackEventsRuleF510C733": { + "Type": "AWS::Events::Rule", + "Properties": { + "ScheduleExpression": "rate(5 minutes)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Ref": "testeventsrulestepfunctionstackStateMachine48534048" + }, + "Id": "Target0", + "RoleArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionstackEventsRuleRole6AD4C16A", + "Arn" + ] + } + } + ] + } + }, + "testeventsrulestepfunctionstackExecutionFailedAlarm865F1B9B": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that failed exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionstackStateMachine48534048" + } + } + ], + "MetricName": "ExecutionsFailed", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "testeventsrulestepfunctionstackExecutionThrottledAlarm25CE7A69": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that throttled exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionstackStateMachine48534048" + } + } + ], + "MetricName": "ExecutionThrottled", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "testeventsrulestepfunctionstackExecutionAbortedAlarmADD2893F": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that aborted exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionstackStateMachine48534048" + } + } + ], + "MetricName": "ExecutionsAborted", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Maximum", + "Threshold": 1 + } + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.ts new file mode 100644 index 000000000..a18709e40 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-no-argument.ts @@ -0,0 +1,36 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +/// !cdk-integ * +import { App, Stack } from "@aws-cdk/core"; +import { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } from "../lib"; +import { Duration } from '@aws-cdk/core'; +import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; +import * as events from '@aws-cdk/aws-events'; + +const app = new App(); +const stack = new Stack(app, 'test-events-rule-step-function-stack'); + +const startState = new stepfunctions.Pass(stack, 'StartState'); + +const props: EventsRuleToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } +}; + +new EventsRuleToStepFunction(stack, 'test-events-rule-step-function-stack', props); +app.synth(); diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.expected.json b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.expected.json new file mode 100644 index 000000000..dc5c18bde --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.expected.json @@ -0,0 +1,412 @@ +{ + "Resources": { + "LambdaFunctionServiceRole0C4CDE0B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/lambda/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LambdaFunctionServiceRolePolicy" + } + ] + } + }, + "LambdaFunctionBF21E41F": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cS3Bucket1F467BCC" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cS3VersionKey9E4F7872" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cS3VersionKey9E4F7872" + } + ] + } + ] + } + ] + ] + } + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionServiceRole0C4CDE0B", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Environment": { + "Variables": { + "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" + } + } + }, + "DependsOn": [ + "LambdaFunctionServiceRole0C4CDE0B" + ], + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W58", + "reason": "Lambda functions has the required permission to write CloudWatch Logs. It uses custom policy instead of arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole with more tighter permissions." + } + ] + } + } + }, + "testeventsrulestepfunctionandlambdastackStateMachineLogGroup5FA8F5A3": { + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "testeventsrulestepfunctionandlambdastackStateMachineRole77040795": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "testeventsrulestepfunctionandlambdastackStateMachineRoleDefaultPolicy7FB04121": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries" + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "LambdaFunctionBF21E41F", + "Arn" + ] + } + }, + { + "Action": [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "testeventsrulestepfunctionandlambdastackStateMachineRoleDefaultPolicy7FB04121", + "Roles": [ + { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachineRole77040795" + } + ] + }, + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations" + } + ] + } + } + }, + "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"StartState\",\"States\":{\"StartState\":{\"Type\":\"Pass\",\"Next\":\"LambdaTask\"},\"LambdaTask\":{\"End\":true,\"Parameters\":{\"FunctionName\":\"", + { + "Ref": "LambdaFunctionBF21E41F" + }, + "\",\"Payload.$\":\"$\"},\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::lambda:invoke\"}},\"TimeoutSeconds\":300}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionandlambdastackStateMachineRole77040795", + "Arn" + ] + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionandlambdastackStateMachineLogGroup5FA8F5A3", + "Arn" + ] + } + } + } + ], + "Level": "ERROR" + } + }, + "DependsOn": [ + "testeventsrulestepfunctionandlambdastackStateMachineRoleDefaultPolicy7FB04121", + "testeventsrulestepfunctionandlambdastackStateMachineRole77040795" + ] + }, + "testeventsrulestepfunctionandlambdastackEventsRuleRole1FC528B4": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "testeventsrulestepfunctionandlambdastackEventsRuleRoleDefaultPolicyCA432EB7": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "testeventsrulestepfunctionandlambdastackEventsRuleRoleDefaultPolicyCA432EB7", + "Roles": [ + { + "Ref": "testeventsrulestepfunctionandlambdastackEventsRuleRole1FC528B4" + } + ] + } + }, + "testeventsrulestepfunctionandlambdastackEventsRule5C68D98F": { + "Type": "AWS::Events::Rule", + "Properties": { + "ScheduleExpression": "rate(5 minutes)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432" + }, + "Id": "Target0", + "RoleArn": { + "Fn::GetAtt": [ + "testeventsrulestepfunctionandlambdastackEventsRuleRole1FC528B4", + "Arn" + ] + } + } + ] + } + }, + "testeventsrulestepfunctionandlambdastackExecutionFailedAlarm1E10C548": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that failed exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432" + } + } + ], + "MetricName": "ExecutionsFailed", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "testeventsrulestepfunctionandlambdastackExecutionThrottledAlarm19B70D6A": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that throttled exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432" + } + } + ], + "MetricName": "ExecutionThrottled", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "testeventsrulestepfunctionandlambdastackExecutionAbortedAlarm8EC0918C": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that aborted exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "testeventsrulestepfunctionandlambdastackStateMachine3BC6D432" + } + } + ], + "MetricName": "ExecutionsAborted", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Maximum", + "Threshold": 1 + } + } + }, + "Parameters": { + "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cS3Bucket1F467BCC": { + "Type": "String", + "Description": "S3 bucket for asset \"42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198c\"" + }, + "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cS3VersionKey9E4F7872": { + "Type": "String", + "Description": "S3 key for asset version \"42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198c\"" + }, + "AssetParameters42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198cArtifactHash00A70A91": { + "Type": "String", + "Description": "Artifact hash for asset \"42a35bbf0dec9ef0ac5b0dde87e71a1b8929e8d2d178dd09ccfb2c928ec0198c\"" + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.ts b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.ts new file mode 100644 index 000000000..ce2b44af4 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/integ.events-rule-step-function-with-lambda.ts @@ -0,0 +1,50 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +/// !cdk-integ * +import { App, Stack } from "@aws-cdk/core"; +import { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } from "../lib"; +import { Duration } from '@aws-cdk/core'; +import * as tasks from '@aws-cdk/aws-stepfunctions-tasks'; +import * as events from '@aws-cdk/aws-events'; +import * as lambda from '@aws-cdk/aws-lambda'; +import { deployLambdaFunction } from '@aws-solutions-constructs/core'; +import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; + +const app = new App(); +const stack = new Stack(app, 'test-events-rule-step-function-and-lambda-stack'); + +const submitLambda = deployLambdaFunction(stack, { + runtime: lambda.Runtime.NODEJS_12_X, + code: lambda.Code.asset(`${__dirname}/lambda`), + handler: 'index.handler' +}); + +const submitJob = new tasks.RunLambdaTask(submitLambda); +const startState = new stepfunctions.Pass(stack, 'StartState'); +startState.next(new stepfunctions.Task(stack, 'LambdaTask', { + task: submitJob +})); + +const props: EventsRuleToStepFunctionProps = { + stateMachineProps: { + definition: startState, + timeout: Duration.minutes(5) + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } +}; + +new EventsRuleToStepFunction(stack, 'test-events-rule-step-function-and-lambda-stack', props); +app.synth(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-events-rule-step-function/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.gitignore b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.npmignore b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/README.md rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md index 7721dcd4e..f2ff14a3a 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-iot-kinesisfirehose-s3/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_iot_kinesisfirehose_s3`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_iot_kinesisfirehose_s3`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-iot-kinesisfirehose-s3`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.iotkinesisfirehoses3`| -This AWS Solutions Konstruk implements an AWS IoT MQTT topic rule to send data to an Amazon Kinesis Data Firehose delivery stream connected to an Amazon S3 bucket. +This AWS Solutions Construct implements an AWS IoT MQTT topic rule to send data to an Amazon Kinesis Data Firehose delivery stream connected to an Amazon S3 bucket. Here is a minimal deployable pattern definition: ``` javascript -const { IotToKinesisFirehoseToS3Props, IotToKinesisFirehoseToS3 } = require('@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3'); +const { IotToKinesisFirehoseToS3Props, IotToKinesisFirehoseToS3 } = require('@aws-solutions-constructs/aws-iot-kinesisfirehose-s3'); const props: IotToKinesisFirehoseToS3Props = { iotTopicRuleProps: { @@ -71,9 +70,29 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|kinesisFirehose()|[`kinesisfirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct| -|bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| -|iotTopicRule()|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| +|kinesisFirehose|[`kinesisfirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| +|iotTopicRule|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| +|iotActionsRole|[`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 IoT Rule| +|kinesisFirehoseRole|[`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 Kinesis Data Firehose delivery stream| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon IoT Rule +* Configure least privilege access IAM role for Amazon IoT + +### Amazon Kinesis Firehose +* Enable CloudWatch logging for Kinesis Firehose +* Configure least privilege access IAM role for Amazon Kinesis Firehose + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/architecture.png b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/lib/index.ts similarity index 66% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/lib/index.ts index 58ff91db5..784565546 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/lib/index.ts @@ -16,9 +16,9 @@ import * as iot from '@aws-cdk/aws-iot'; import * as s3 from '@aws-cdk/aws-s3'; import * as iam from '@aws-cdk/aws-iam'; import { Construct } from '@aws-cdk/core'; -import * as defaults from '@aws-solutions-konstruk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; -import { KinesisFirehoseToS3 } from '@aws-solutions-konstruk/aws-kinesisfirehose-s3'; +import * as defaults from '@aws-solutions-constructs/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; +import { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3'; /** * @summary The properties for the IotToKinesisFirehoseToS3 Construct @@ -60,9 +60,11 @@ export interface IotToKinesisFirehoseToS3Props { } export class IotToKinesisFirehoseToS3 extends Construct { - private topic: iot.CfnTopicRule; - private firehose: kinesisfirehose.CfnDeliveryStream; - private s3Bucket: s3.Bucket; + public readonly iotTopicRule: iot.CfnTopicRule; + public readonly kinesisFirehose: kinesisfirehose.CfnDeliveryStream; + public readonly s3Bucket: s3.Bucket; + public readonly iotActionsRole: iam.Role; + public readonly kinesisFirehoseRole: iam.Role; /** * @summary Constructs a new instance of the IotToKinesisFirehoseToS3 class. @@ -81,11 +83,11 @@ export class IotToKinesisFirehoseToS3 extends Construct { existingBucketObj: props.existingBucketObj, bucketProps: props.bucketProps }); - this.firehose = firehoseToS3.kinesisFirehose(); - this.s3Bucket = firehoseToS3.bucket(); + this.kinesisFirehose = firehoseToS3.kinesisFirehose; + this.s3Bucket = firehoseToS3.s3Bucket; // Setup the IAM Role for IoT Actions - const iotActionsRole = new iam.Role(this, 'IotActionsRole', { + this.iotActionsRole = new iam.Role(this, 'IotActionsRole', { assumedBy: new iam.ServicePrincipal('iot.amazonaws.com'), }); @@ -95,52 +97,24 @@ export class IotToKinesisFirehoseToS3 extends Construct { actions: [ 'firehose:PutRecord' ], - resources: [this.firehose.attrArn] + resources: [this.kinesisFirehose.attrArn] }) ]}); // Attach policy to role - iotActionsPolicy.attachToRole(iotActionsRole); + iotActionsPolicy.attachToRole(this.iotActionsRole); const defaultIotTopicProps = defaults.DefaultCfnTopicRuleProps([{ firehose: { - deliveryStreamName: this.firehose.ref, - roleArn: iotActionsRole.roleArn + deliveryStreamName: this.kinesisFirehose.ref, + roleArn: this.iotActionsRole.roleArn } }]); const iotTopicProps = overrideProps(defaultIotTopicProps, props.iotTopicRuleProps, true); // Create the IoT topic rule - this.topic = new iot.CfnTopicRule(this, 'IotTopic', iotTopicProps); - } + this.iotTopicRule = new iot.CfnTopicRule(this, 'IotTopic', iotTopicProps); - /** - * @summary Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct. - * @returns {kinesisfirehose.CfnDeliveryStream} Instance of CfnDeliveryStream created by the construct - * @since 0.8.0 - * @access public - */ - public kinesisFirehose(): kinesisfirehose.CfnDeliveryStream { - return this.firehose as kinesisfirehose.CfnDeliveryStream; - } - - /** - * @summary Returns an instance of s3.Bucket created by the construct. - * @returns {s3.Bucket} Instance of s3.Bucket created by the construct - * @since 0.8.0 - * @access public - */ - public bucket(): s3.Bucket { - return this.s3Bucket; - } - - /** - * @summary Returns an instance of iot.CfnTopicRule created by the construct. - * @returns {iot.CfnTopicRule} Instance of CfnTopicRule created by the construct - * @since 0.8.0 - * @access public - */ - public iotTopicRule(): iot.CfnTopicRule { - return this.topic; + this.kinesisFirehoseRole = firehoseToS3.kinesisFirehoseRole; } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/package.json b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/package.json similarity index 53% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/package.json rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/package.json index 37b75e72f..675d7137a 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-iot-kinesisfirehose-s3", + "version": "1.46.0", "description": "CDK Constructs for AWS IoT to AWS Kinesis Firehose to AWS S3 integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3" }, "author": { "name": "Amazon Web Services", @@ -33,36 +33,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.iotkinesisfirehoses3", + "package": "software.amazon.awsconstructs.services.iotkinesisfirehoses3", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "iotkinesisfirehoses3" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.IotKinesisfirehoseS3", - "packageId": "Amazon.Konstruk.AWS.IotKinesisfirehoseS3", + "namespace": "Amazon.Constructs.AWS.IotKinesisfirehoseS3", + "packageId": "Amazon.Constructs.AWS.IotKinesisfirehoseS3", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-iot-kinesisfirehose-s3", - "module": "aws_solutions_konstruk.aws_iot_kinesisfirehose_s3" + "distName": "aws-solutions-constructs.aws-iot-kinesisfirehose-s3", + "module": "aws_solutions_constructs.aws_iot_kinesisfirehose_s3" } } }, "dependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-kinesisfirehose-s3": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-kinesisfirehose-s3": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -72,13 +72,13 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-kinesisfirehose-s3": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-kinesisfirehose-s3": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/__snapshots__/test.iot-kinesisfirehose-s3.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/__snapshots__/test.iot-kinesisfirehose-s3.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/__snapshots__/test.iot-kinesisfirehose-s3.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/__snapshots__/test.iot-kinesisfirehose-s3.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts index a78b694fb..1c2380a79 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/test/test.iot-kinesisfirehose-s3.test.ts @@ -14,7 +14,6 @@ import { SynthUtils } from '@aws-cdk/assert'; import { IotToKinesisFirehoseToS3, IotToKinesisFirehoseToS3Props } from "../lib"; import * as cdk from "@aws-cdk/core"; -import * as iot from '@aws-cdk/aws-iot'; import '@aws-cdk/assert/jest'; function deploy(stack: cdk.Stack) { @@ -115,12 +114,14 @@ test('check firehose and s3 overrides', () => { } }}); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: IotToKinesisFirehoseToS3 = deploy(stack); - expect(construct.iotTopicRule()).toBeInstanceOf(iot.CfnTopicRule); - expect(construct.kinesisFirehose()).toBeDefined(); - expect(construct.bucket()).toBeDefined(); + expect(construct.iotTopicRule !== null); + expect(construct.kinesisFirehose !== null); + expect(construct.s3Bucket !== null); + expect(construct.iotActionsRole !== null); + expect(construct.kinesisFirehoseRole !== null); }); diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md similarity index 63% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/README.md rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md index 41357451e..2697ef9a4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-iot-lambda-dynamodb/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_iot_lambda_dynamodb`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-iot-lambda-dynamodb`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_iot_lambda_dynamodb`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-iot-lambda-dynamodb`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.iotlambdadynamodb`| -This AWS Solutions Konstruk implements an AWS IoT topic rule, an AWS Lambda function and Amazon DynamoDB table with the least privileged permissions. +This AWS Solutions Construct implements an AWS IoT topic rule, an AWS Lambda function and Amazon DynamoDB table with the least privileged permissions. Here is a minimal deployable pattern definition: ``` javascript -const { IotToLambdaToDynamoDBProps, IotToLambdaToDynamoDB } = require('@aws-solutions-konstruk/aws-iot-lambda-dynamodb'); +const { IotToLambdaToDynamoDBProps, IotToLambdaToDynamoDB } = require('@aws-solutions-constructs/aws-iot-lambda-dynamodb'); const props: IotToLambdaToDynamoDBProps = { deployLambda: true, @@ -77,9 +76,26 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|iotTopicRule()|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| -|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| +|iotTopicRule|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|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| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon IoT Rule +* Configure least privilege access IAM role for Amazon IoT + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon DynamoDB Table +* Set the billing mode for DynamoDB Table to On-Demand (Pay per request) +* Enable server-side encryption for DynamoDB Table using AWS managed KMS Key +* Creates a partition key called 'id' for DynamoDB Table +* Retain the Table when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/architecture.png b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/lib/index.ts similarity index 68% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/lib/index.ts index 6bc12e73e..92f3fc70a 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/lib/index.ts @@ -14,8 +14,8 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as iot from '@aws-cdk/aws-iot'; import * as dynamodb from '@aws-cdk/aws-dynamodb'; -import { IotToLambda } from '@aws-solutions-konstruk/aws-iot-lambda'; -import { LambdaToDynamoDB } from '@aws-solutions-konstruk/aws-lambda-dynamodb'; +import { IotToLambda } from '@aws-solutions-constructs/aws-iot-lambda'; +import { LambdaToDynamoDB } from '@aws-solutions-constructs/aws-lambda-dynamodb'; import { Construct } from '@aws-cdk/core'; /** @@ -58,9 +58,9 @@ export interface IotToLambdaToDynamoDBProps { } export class IotToLambdaToDynamoDB extends Construct { - private topic: iot.CfnTopicRule; - private fn: lambda.Function; - private table: dynamodb.Table; + public readonly iotTopicRule: iot.CfnTopicRule; + public readonly lambdaFunction: lambda.Function; + public readonly dynamoTable: dynamodb.Table; /** * @summary Constructs a new instance of the IotToLambdaToDynamoDB class. @@ -75,45 +75,15 @@ export class IotToLambdaToDynamoDB extends Construct { // Setup the IotToLambda const iotToLambda = new IotToLambda(this, 'IotToLambda', props); - this.topic = iotToLambda.iotTopicRule(); - this.fn = iotToLambda.lambdaFunction(); + this.iotTopicRule = iotToLambda.iotTopicRule; + this.lambdaFunction = iotToLambda.lambdaFunction; // Setup the LambdaToDynamoDB const lambdaToDynamoDB = new LambdaToDynamoDB(this, 'LambdaToDynamoDB', { deployLambda: false, - existingLambdaObj: this.fn, + existingLambdaObj: this.lambdaFunction, dynamoTableProps: props.dynamoTableProps }); - this.table = lambdaToDynamoDB.dynamoTable(); - } - - /** - * @summary Returns an instance of iot.CfnTopicRule created by the construct. - * @returns {iot.CfnTopicRule} Instance of CfnTopicRule created by the construct - * @since 0.8.0 - * @access public - */ - public iotTopicRule(): iot.CfnTopicRule { - return this.topic; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of dynamodb.Table created by the construct. - * @returns {dynamodb.Table} Instance of dynamodb.Table created by the construct - * @since 0.8.0 - * @access public - */ - public dynamoTable(): dynamodb.Table { - return this.table; + this.dynamoTable = lambdaToDynamoDB.dynamoTable; } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/package.json b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/package.json similarity index 54% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/package.json rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/package.json index 53a7e299f..be864dd3c 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-iot-lambda-dynamodb", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-iot-lambda-dynamodb", + "version": "1.46.0", "description": "CDK Constructs for AWS IoT to AWS Lambda to AWS DyanmoDB integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb" }, "author": { "name": "Amazon Web Services", @@ -34,36 +34,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.iotlambdadynamodb", + "package": "software.amazon.awsconstructs.services.iotlambdadynamodb", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "iotlambdadynamodb" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.IotLambdaDynamodb", - "packageId": "Amazon.Konstruk.AWS.IotLambdaDynamodb", + "namespace": "Amazon.Constructs.AWS.IotLambdaDynamodb", + "packageId": "Amazon.Constructs.AWS.IotLambdaDynamodb", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-iot-lambda-dynamodb", - "module": "aws_solutions_konstruk.aws_iot_lambda_dynamodb" + "distName": "aws-solutions-constructs.aws-iot-lambda-dynamodb", + "module": "aws_solutions_constructs.aws_iot_lambda_dynamodb" } } }, "dependencies": { - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-iot-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-dynamodb": "~0.8.1", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-iot-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-dynamodb": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,13 +73,13 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-iot-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-dynamodb": "~0.8.1", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-iot-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-dynamodb": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/__snapshots__/iot-lambda-dynamodb.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/__snapshots__/iot-lambda-dynamodb.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/__snapshots__/iot-lambda-dynamodb.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/__snapshots__/iot-lambda-dynamodb.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.expected.json b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.expected.json rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/integ.iot-lambda-dynamodb.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts index d2b4fe3f5..2ebf1473e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts @@ -240,14 +240,14 @@ test('check lambda function policy ', () => { }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: IotToLambdaToDynamoDB = deployStack(stack); - expect(construct.lambdaFunction()).toBeDefined(); - expect(construct.dynamoTable()).toBeDefined(); - expect(construct.iotTopicRule()).toBeDefined(); + expect(construct.lambdaFunction !== null); + expect(construct.dynamoTable !== null); + expect(construct.iotTopicRule !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.gitignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.npmignore b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md similarity index 69% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md index 01b7b51e4..bb68f1712 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-iot-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_iot_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-iot-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_iot_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-iot-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.iotlambda`| -This AWS Solutions Konstruk implements an AWS IoT MQTT topic rule and an AWS Lambda function pattern. +This AWS Solutions Construct implements an AWS IoT MQTT topic rule and an AWS Lambda function pattern. Here is a minimal deployable pattern definition: ``` javascript -const { IotToLambdaProps, IotToLambda } = require('@aws-solutions-konstruk/aws-iot-lambda'); +const { IotToLambdaProps, IotToLambda } = require('@aws-solutions-constructs/aws-iot-lambda'); const props: IotToLambdaProps = { deployLambda: true, @@ -75,8 +74,19 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|iotTopicRule()|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|iotTopicRule|[`iot.CfnTopicRule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iot.CfnTopicRule.html)|Returns an instance of iot.CfnTopicRule created by the construct| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon IoT Rule +* Configure least privilege access IAM role for Amazon IoT + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/lib/index.ts similarity index 72% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/lib/index.ts index 3b809426e..cf3d61dc0 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/lib/index.ts @@ -15,8 +15,8 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as iot from '@aws-cdk/aws-iot'; import * as iam from '@aws-cdk/aws-iam'; import { Construct } from '@aws-cdk/core'; -import * as defaults from '@aws-solutions-konstruk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; /** * @summary The properties for the IotToLambda class. @@ -52,8 +52,8 @@ export interface IotToLambdaProps { } export class IotToLambda extends Construct { - private fn: lambda.Function; - private topic: iot.CfnTopicRule; + public readonly lambdaFunction: lambda.Function; + public readonly iotTopicRule: iot.CfnTopicRule; /** * @summary Constructs a new instance of the IotToLambda class. @@ -66,7 +66,7 @@ export class IotToLambda extends Construct { constructor(scope: Construct, id: string, props: IotToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -74,38 +74,17 @@ export class IotToLambda extends Construct { const defaultIotTopicProps = defaults.DefaultCfnTopicRuleProps([{ lambda: { - functionArn: this.fn.functionArn + functionArn: this.lambdaFunction.functionArn } }]); const iotTopicProps = overrideProps(defaultIotTopicProps, props.iotTopicRuleProps, true); // Create the IoT topic rule - this.topic = new iot.CfnTopicRule(this, 'IotTopic', iotTopicProps); + this.iotTopicRule = new iot.CfnTopicRule(this, 'IotTopic', iotTopicProps); - this.fn.addPermission("LambdaInvokePermission", { + this.lambdaFunction.addPermission("LambdaInvokePermission", { principal: new iam.ServicePrincipal('iot.amazonaws.com'), - sourceArn: this.topic.attrArn + sourceArn: this.iotTopicRule.attrArn }); } - - /** - * @summary Returns an instance of iot.CfnTopicRule created by the construct. - * @returns {iot.CfnTopicRule} Instance of CfnTopicRule created by the construct - * @since 0.8.0 - * @access public - */ - public iotTopicRule(): iot.CfnTopicRule { - return this.topic; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - } diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/package.json similarity index 60% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/package.json index 6a96d10ae..1a9a300cd 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-iot-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-iot-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS IoT to AWS Lambda integration", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-iot-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-iot-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,34 +34,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.iotlambda", + "package": "software.amazon.awsconstructs.services.iotlambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "iotlambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.IotLambda", - "packageId": "Amazon.Konstruk.AWS.IotLambda", + "namespace": "Amazon.Constructs.AWS.IotLambda", + "packageId": "Amazon.Constructs.AWS.IotLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-iot-lambda", - "module": "aws_solutions_konstruk.aws_iot_lambda" + "distName": "aws-solutions-constructs.aws-iot-lambda", + "module": "aws_solutions_constructs.aws_iot_lambda" } } }, "dependencies": { - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,11 +71,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-iam": "~1.40.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/__snapshots__/iot-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/__snapshots__/iot-lambda.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/__snapshots__/iot-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/__snapshots__/iot-lambda.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-new-func.expected.json b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-new-func.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-new-func.expected.json rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-new-func.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-new-func.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-new-func.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-new-func.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-new-func.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.expected.json b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.expected.json rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts index c6f74df93..609b8f7ce 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/integ.iot-lambda-use-existing-func.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { IotToLambda, IotToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // Setup const app = new App(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/iot-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/iot-lambda.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/iot-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/iot-lambda.test.ts index b133edfae..6c7d9b4a2 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-iot-lambda/test/iot-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/iot-lambda.test.ts @@ -14,7 +14,6 @@ import { SynthUtils } from '@aws-cdk/assert'; import { IotToLambda, IotToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as iot from '@aws-cdk/aws-iot'; import * as cdk from "@aws-cdk/core"; import '@aws-cdk/assert/jest'; @@ -265,13 +264,13 @@ test('check iot lambda function role for deploy: false', () => { }); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: IotToLambda = deployNewFunc(stack); - expect(construct.iotTopicRule()).toBeInstanceOf(iot.CfnTopicRule); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); + expect(construct.iotTopicRule !== null); + expect(construct.lambdaFunction !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/core/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-iot-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.gitignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.npmignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md similarity index 66% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md index c5ab3a024..cedbf9544 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,23 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-kinesisfirehose-s3-and-kinesisanalytics/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_kinesisfirehose_s3_and_kinesisanalytics`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_kinesisfirehose_s3_and_kinesisanalytics`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.kinesisfirehoses3kinesisanalytics`| -This AWS Solutions Konstruk implements an Amazon Kinesis Firehose delivery stream connected to: -1. An Amazon S3 bucket, and -1. An Amazon Kinesis Analytics application. +This AWS Solutions Construct implements an Amazon Kinesis Firehose delivery stream connected to an Amazon S3 bucket, and an Amazon Kinesis Analytics application. Here is a minimal deployable pattern definition: ``` javascript -const { KinesisFirehoseToAnalyticsAndS3 } = require('@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics'); +const { KinesisFirehoseToAnalyticsAndS3 } = require('@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics'); new KinesisFirehoseToAnalyticsAndS3(stack, 'FirehoseToS3AndAnalyticsPattern', { kinesisAnalyticsProps: { @@ -91,9 +88,27 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|kinesisAnalytics()|[`kinesisAnalytics.CfnApplication`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisanalytics.CfnApplication.html)|Returns an instance of the Kinesis Analytics application created by the pattern.| -|kinesisFirehose()|[`kinesisFirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of the Kinesis Firehose delivery stream created by the pattern.| -|bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the S3 bucket created by the pattern.| +|kinesisAnalytics|[`kinesisAnalytics.CfnApplication`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisanalytics.CfnApplication.html)|Returns an instance of the Kinesis Analytics application created by the pattern.| +|kinesisFirehose|[`kinesisFirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of the Kinesis Firehose delivery stream created by the pattern.| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the S3 bucket created by the pattern.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon Kinesis Firehose +* Enable CloudWatch logging for Kinesis Firehose +* Configure least privilege access IAM role for Amazon Kinesis Firehose + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack + +### Amazon Kinesis Data Analytics +* Configure least privilege access IAM role for Amazon Kinesis Analytics ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/architecture.png b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts similarity index 68% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts index f89cbd4c8..352a7836b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/lib/index.ts @@ -14,9 +14,9 @@ // Imports import * as kinesisFirehose from '@aws-cdk/aws-kinesisfirehose'; import * as kinesisAnalytics from '@aws-cdk/aws-kinesisanalytics'; -import { KinesisFirehoseToS3, KinesisFirehoseToS3Props } from '@aws-solutions-konstruk/aws-kinesisfirehose-s3'; +import { KinesisFirehoseToS3, KinesisFirehoseToS3Props } from '@aws-solutions-constructs/aws-kinesisfirehose-s3'; import * as s3 from '@aws-cdk/aws-s3'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -62,10 +62,9 @@ export interface KinesisFirehoseToAnalyticsAndS3Props { * @summary The KinesisFirehoseToAnalyticsAndS3 class. */ export class KinesisFirehoseToAnalyticsAndS3 extends Construct { - - // Declarations - private analytics: kinesisAnalytics.CfnApplication; - private kfs: KinesisFirehoseToS3; + public readonly kinesisAnalytics: kinesisAnalytics.CfnApplication; + public readonly kinesisFirehose: kinesisFirehose.CfnDeliveryStream; + public readonly s3Bucket: s3.Bucket; /** * @summary Constructs a new instance of the KinesisFirehoseToAnalyticsAndS3 class. @@ -87,42 +86,15 @@ export class KinesisFirehoseToAnalyticsAndS3 extends Construct { }; // Add the kinesisfirehose-s3 pattern - this.kfs = new KinesisFirehoseToS3(this, 'KinesisFirehoseToS3', kinesisFirehoseToS3Props); + const kfs = new KinesisFirehoseToS3(this, 'KinesisFirehoseToS3', kinesisFirehoseToS3Props); // Add the Kinesis Analytics application - this.analytics = defaults.buildKinesisAnalyticsApp(this, { - kinesisFirehose: this.kfs.kinesisFirehose(), + this.kinesisAnalytics = defaults.buildKinesisAnalyticsApp(this, { + kinesisFirehose: kfs.kinesisFirehose, kinesisAnalyticsProps: props.kinesisAnalyticsProps }); - } - - /** - * @summary Returns an instance of the kinesisAnalytics.CfnApplication created by the construct. - * @returns {kinesisAnalytics.CfnApplication} Instance of the CfnApplication created by the construct. - * @since 0.8.0 - * @access public - */ - public kinesisAnalytics(): kinesisAnalytics.CfnApplication { - return this.analytics; - } - - /** - * @summary Returns an instance of the kinesisFirehose.CfnDeliveryStream created by the construct. - * @returns {kinesisFirehose.CfnDeliveryStream} Instance of the CfnDeliveryStream created by the construct. - * @since 0.8.0 - * @access public - */ - public kinesisFirehose(): kinesisFirehose.CfnDeliveryStream { - return this.kfs.kinesisFirehose(); - } - /** - * @summary Returns an instance of the s3.Bucket created by the construct. - * @returns {s3.Bucket} Instance of the Bucket created by the construct. - * @since 0.8.0 - * @access public - */ - public bucket(): s3.Bucket { - return this.kfs.bucket(); + this.kinesisFirehose = kfs.kinesisFirehose; + this.s3Bucket = kfs.s3Bucket; } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json similarity index 52% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json index c5db98572..e2b4d1298 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an Amazon Kinesis Data Firehose delivery stream and (1) an Amazon S3 bucket, and (2) an Amazon Kinesis Data Analytics application.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics" }, "author": { "name": "Amazon Web Services", @@ -33,37 +33,37 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.kinesisfirehoses3kinesisanalytics", + "package": "software.amazon.awsconstructs.services.kinesisfirehoses3kinesisanalytics", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "kinesisfirehoses3kinesisanalytics" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.KinesisFirehoseS3KinesisAnalytics", - "packageId": "Amazon.Konstruk.AWS.KinesisFirehoseS3KinesisAnalytics", + "namespace": "Amazon.Constructs.AWS.KinesisFirehoseS3KinesisAnalytics", + "packageId": "Amazon.Constructs.AWS.KinesisFirehoseS3KinesisAnalytics", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-kinesis-firehose-s3-kinesis-analytics", - "module": "aws_solutions_konstruk.aws_kinesis_firehose_s3_kinesis_analytics" + "distName": "aws-solutions-constructs.aws-kinesis-firehose-s3-kinesis-analytics", + "module": "aws_solutions_constructs.aws_kinesis_firehose_s3_kinesis_analytics" } } }, "dependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kinesisanalytics": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-kinesisfirehose-s3": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kinesisanalytics": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-kinesisfirehose-s3": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,14 +73,14 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kinesisanalytics": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-kinesisfirehose-s3": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kinesisanalytics": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-kinesisfirehose-s3": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/__snapshots__/test.kinesisfirehose-analytics-s3.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/__snapshots__/test.kinesisfirehose-analytics-s3.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/__snapshots__/test.kinesisfirehose-analytics-s3.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/__snapshots__/test.kinesisfirehose-analytics-s3.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts index 3386d44d7..22733f158 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/test/test.kinesisfirehose-analytics-s3.test.ts @@ -61,7 +61,7 @@ test('Pattern deployment w/ default properties', () => { // -------------------------------------------------------------- // Test Case 2 - Test the getter methods // -------------------------------------------------------------- -test('Test getter methods', () => { +test('Test properties', () => { // Initial Setup const stack = new Stack(); const props: KinesisFirehoseToAnalyticsAndS3Props = { @@ -94,7 +94,7 @@ test('Test getter methods', () => { }; const app = new KinesisFirehoseToAnalyticsAndS3(stack, 'test-kinesis-firehose-kinesis-analytics', props); // Assertions - expect(app.kinesisAnalytics()).toBeDefined(); - expect(app.kinesisFirehose()).toBeDefined(); - expect(app.bucket()).toBeDefined(); + expect(app.kinesisAnalytics !== null); + expect(app.kinesisFirehose !== null); + expect(app.s3Bucket !== null); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.gitignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md similarity index 59% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/README.md rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md index 13a8c88aa..9885c2845 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-kinesisfirehose-s3/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_kinesisfirehose_s3`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-kinesisfirehose-s3`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_kinesisfirehose_s3`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-kinesisfirehose-s3`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.kinesisfirehoses3`| -This AWS Solutions Konstruk implements an Amazon Kinesis Data Firehose delivery stream connected to an Amazon S3 bucket. +This AWS Solutions Construct implements an Amazon Kinesis Data Firehose delivery stream connected to an Amazon S3 bucket. Here is a minimal deployable pattern definition: ``` javascript -const { KinesisFirehoseToS3 } = require('@aws-solutions-konstruk/aws-kinesisfirehose-s3'); +const { KinesisFirehoseToS3 } = require('@aws-solutions-constructs/aws-kinesisfirehose-s3'); new KinesisFirehoseToS3(stack, 'test-firehose-s3', {}); @@ -59,8 +58,24 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|kinesisFirehose()|[`kinesisfirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct| -|bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| +|kinesisFirehose|[`kinesisfirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct| +|kinesisFirehoseRole|[`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 Kinesis Data Firehose delivery stream| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon Kinesis Firehose +* Enable CloudWatch logging for Kinesis Firehose +* Configure least privilege access IAM role for Amazon Kinesis Firehose + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/architecture.png b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/lib/index.ts similarity index 82% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/lib/index.ts index c32d3af0e..a1e5c0a46 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/lib/index.ts @@ -14,9 +14,9 @@ import * as kinesisfirehose from '@aws-cdk/aws-kinesisfirehose'; import { Construct } from '@aws-cdk/core'; import * as s3 from '@aws-cdk/aws-s3'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import * as iam from '@aws-cdk/aws-iam'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; @@ -54,10 +54,9 @@ export interface KinesisFirehoseToS3Props { } export class KinesisFirehoseToS3 extends Construct { - - // Private variables - private firehose: kinesisfirehose.CfnDeliveryStream; - private s3Bucket: s3.Bucket; + public readonly kinesisFirehose: kinesisfirehose.CfnDeliveryStream; + public readonly kinesisFirehoseRole: iam.Role; + public readonly s3Bucket: s3.Bucket; /** * Constructs a new instance of the IotToLambda class. @@ -89,7 +88,7 @@ export class KinesisFirehoseToS3 extends Construct { const cwLogStream: logs.LogStream = cwLogGroup.addStream('firehose-log-stream'); // Setup the IAM Role for Kinesis Firehose - const firehoseRole = new iam.Role(this, 'KinesisFirehoseRole', { + this.kinesisFirehoseRole = new iam.Role(this, 'KinesisFirehoseRole', { assumedBy: new iam.ServicePrincipal('firehose.amazonaws.com'), }); @@ -115,33 +114,19 @@ export class KinesisFirehoseToS3 extends Construct { ]}); // Attach policy to role - firehosePolicy.attachToRole(firehoseRole); + firehosePolicy.attachToRole(this.kinesisFirehoseRole); // Setup the default Kinesis Firehose props const defaultKinesisFirehoseProps: kinesisfirehose.CfnDeliveryStreamProps = - defaults.DefaultCfnDeliveryStreamProps(this.s3Bucket.bucketArn, firehoseRole.roleArn, + defaults.DefaultCfnDeliveryStreamProps(this.s3Bucket.bucketArn, this.kinesisFirehoseRole.roleArn, cwLogGroup.logGroupName, cwLogStream.logStreamName); // Override with the input props if (props.kinesisFirehoseProps) { const kinesisFirehoseProps = overrideProps(defaultKinesisFirehoseProps, props.kinesisFirehoseProps); - this.firehose = new kinesisfirehose.CfnDeliveryStream(this, 'KinesisFirehose', kinesisFirehoseProps); + this.kinesisFirehose = new kinesisfirehose.CfnDeliveryStream(this, 'KinesisFirehose', kinesisFirehoseProps); } else { - this.firehose = new kinesisfirehose.CfnDeliveryStream(this, 'KinesisFirehose', defaultKinesisFirehoseProps); + this.kinesisFirehose = new kinesisfirehose.CfnDeliveryStream(this, 'KinesisFirehose', defaultKinesisFirehoseProps); } } - - /** - * Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct - */ - public kinesisFirehose(): kinesisfirehose.CfnDeliveryStream { - return this.firehose; - } - - /** - * Returns an instance of s3.Bucket created by the construct - */ - public bucket(): s3.Bucket { - return this.s3Bucket; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/package.json b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/package.json similarity index 57% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/package.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/package.json index 0b3b0f1e4..5da63dbfc 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-kinesisfirehose-s3", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-kinesisfirehose-s3", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an Amazon Kinesis Data Firehose delivery stream and an Amazon S3 bucket.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3" }, "author": { "name": "Amazon Web Services", @@ -33,35 +33,35 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.kinesisfirehoses3", + "package": "software.amazon.awsconstructs.services.kinesisfirehoses3", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "kinesisfirehoses3" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.KinesisFirehoseS3", - "packageId": "Amazon.Konstruk.AWS.KinesisFirehoseS3", + "namespace": "Amazon.Constructs.AWS.KinesisFirehoseS3", + "packageId": "Amazon.Constructs.AWS.KinesisFirehoseS3", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-kinesis-firehose-s3", - "module": "aws_solutions_konstruk.aws_kinesis_firehose_s3" + "distName": "aws-solutions-constructs.aws-kinesis-firehose-s3", + "module": "aws_solutions_constructs.aws_kinesis_firehose_s3" } } }, "dependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,12 +71,12 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/__snapshots__/test.kinesisfirehose-s3.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/__snapshots__/test.kinesisfirehose-s3.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/__snapshots__/test.kinesisfirehose-s3.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/__snapshots__/test.kinesisfirehose-s3.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts similarity index 92% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts index e62d545ac..71040c7ef 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/test/test.kinesisfirehose-s3.test.ts @@ -14,7 +14,6 @@ import { SynthUtils } from '@aws-cdk/assert'; import { KinesisFirehoseToS3, KinesisFirehoseToS3Props } from "../lib"; import * as cdk from '@aws-cdk/core'; -import * as kinesisfirehose from '@aws-cdk/aws-kinesisfirehose'; import '@aws-cdk/assert/jest'; function deploy(stack: cdk.Stack) { @@ -103,11 +102,12 @@ test('test kinesisFirehose override ', () => { }}); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: KinesisFirehoseToS3 = deploy(stack); - expect(construct.kinesisFirehose()).toBeInstanceOf(kinesisfirehose.CfnDeliveryStream); - expect(construct.bucket()).toBeDefined(); + expect(construct.kinesisFirehose !== null); + expect(construct.s3Bucket !== null); + expect(construct.kinesisFirehoseRole !== null); }); diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.npmignore b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md similarity index 65% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md index d70f9de0d..e333b695e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-kinesisstreams-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_kinesisstreams_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-kinesisstreams-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_kinesisstreams_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-kinesisstreams-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.kinesisstreamslambda`| -This AWS Solutions Konstruk deploys a Kinesis Stream and Lambda function with the appropriate resources/properties for interaction and security. +This AWS Solutions Construct deploys a Kinesis Stream and Lambda function with the appropriate resources/properties for interaction and security. Here is a minimal deployable pattern definition: ``` javascript -const { KinesisStreamsToLambda } = require('@aws-solutions-konstruk/aws-kinesisstreams-lambda'); +const { KinesisStreamsToLambda } = require('@aws-solutions-constructs/aws-kinesisstreams-lambda'); new KinesisStreamsToLambda(stack, 'KinesisToLambdaPattern', { deployLambda: true, @@ -66,14 +65,26 @@ _Parameters_ |lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|Optional user-provided props to override the default props for the Lambda function. This property is only required if `deployLambda` is set to true.| |kinesisStreamProps?|[`kinesis.StreamProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesis.StreamProps.html)|Optional user-provided props to override the default props for the Kinesis stream.| |eventSourceProps?|[`lambda.EventSourceMappingOptions`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.EventSourceMappingOptions.html)|Optional user-provided props to override the default props for the Lambda event source mapping.| -|encryptionKeyProps?|[`kms.KeyProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kms.KeyProps.html)|Optional user-provided props to override the default props for the KMS encryption key.| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|stream()|[`kinesis.Stream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesis.Stream.html)|Returns an instance of the Kinesis stream created by the pattern.| -|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.| +|kinesisStream|[`kinesis.Stream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesis.Stream.html)|Returns an instance of the Kinesis stream created by the pattern.| +|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.| +|kinesisStreamRole|[`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 Kinesis stream.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon Kinesis Stream +* Configure least privilege access IAM role for Kinesis Stream +* Enable server-side encryption for Kinesis Stream using AWS Managed KMS Key + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/lib/index.ts similarity index 73% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/lib/index.ts index 199803c54..e34037336 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/lib/index.ts @@ -14,10 +14,9 @@ // Imports import * as lambda from '@aws-cdk/aws-lambda'; import * as kinesis from '@aws-cdk/aws-kinesis'; -import * as kms from '@aws-cdk/aws-kms'; import * as iam from '@aws-cdk/aws-iam'; -import * as defaults from '@aws-solutions-konstruk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -57,22 +56,15 @@ export interface KinesisStreamsToLambdaProps { * @default - Default props are used. */ readonly eventSourceProps?: lambda.EventSourceMappingOptions | any - /** - * Optional user-provided props to override the default props for the KMS encryption key. - * - * @default - Default props are used. - */ - readonly encryptionKeyProps?: kms.KeyProps | any } /** * @summary The KinesisStreamsToLambda class. */ export class KinesisStreamsToLambda extends Construct { - // Private variables - private kinesisStream: kinesis.Stream; - private fn: lambda.Function; - private encryptionKey: kms.Key; + public readonly kinesisStream: kinesis.Stream; + public readonly lambdaFunction: lambda.Function; + public readonly kinesisStreamRole: iam.Role; /** * @summary Constructs a new instance of the KinesisStreamsToLambda class. @@ -85,19 +77,13 @@ export class KinesisStreamsToLambda extends Construct { constructor(scope: Construct, id: string, props: KinesisStreamsToLambdaProps) { super(scope, id); - // Setup the encryption key - this.encryptionKey = defaults.buildEncryptionKey(this, { - encryptionKeyProps: props.encryptionKeyProps - }); - // Setup the Kinesis Stream this.kinesisStream = defaults.buildKinesisStream(this, { - encryptionKey: this.encryptionKey, kinesisStreamProps: props.kinesisStreamProps }); // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -107,11 +93,11 @@ export class KinesisStreamsToLambda extends Construct { const eventSourceProps = (props.eventSourceProps) ? overrideProps(defaults.DefaultKinesisEventSourceProps(this.kinesisStream.streamArn), props.eventSourceProps) : defaults.DefaultKinesisEventSourceProps(this.kinesisStream.streamArn); - this.fn.addEventSourceMapping('LambdaKinesisEventSourceMapping', eventSourceProps); + this.lambdaFunction.addEventSourceMapping('LambdaKinesisEventSourceMapping', eventSourceProps); // Add permissions for the Lambda function to access Kinesis const policy = new iam.Policy(this, 'LambdaFunctionPolicy'); - const role = this.fn.role as iam.Role; + this.kinesisStreamRole = this.lambdaFunction.role as iam.Role; policy.addStatements(new iam.PolicyStatement({ effect: iam.Effect.ALLOW, resources: [ this.kinesisStream.streamArn ], @@ -128,8 +114,8 @@ export class KinesisStreamsToLambda extends Construct { 'kinesis:ListStreams', ] })); - policy.attachToRole(role); - this.kinesisStream.grantRead(this.fn.grantPrincipal); + policy.attachToRole(this.kinesisStreamRole); + this.kinesisStream.grantRead(this.lambdaFunction.grantPrincipal); // Add appropriate cfn_nag metadata const cfnCustomPolicy = policy.node.defaultChild as iam.CfnPolicy; @@ -144,24 +130,4 @@ export class KinesisStreamsToLambda extends Construct { } }; } - - /** - * @summary Returns an instance of the kinesis.Stream created by the construct. - * @returns {kinesis.Stream} Instance of the Stream created by the construct. - * @since 0.8.0 - * @access public - */ - public stream(): kinesis.Stream { - return this.kinesisStream; - } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/package.json similarity index 58% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/package.json index 3fea2344a..64634f5a4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-kinesisstreams-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-kinesisstreams-lambda", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an Amazon Kinesis Data Stream and an AWS Lambda function.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,35 +34,35 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.kinesisstreamslambda", + "package": "software.amazon.awsconstructs.services.kinesisstreamslambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "kinesisstreamslambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.KinesisStreamsLambda", - "packageId": "Amazon.Konstruk.AWS.KinesisStreamsLambda", + "namespace": "Amazon.Constructs.AWS.KinesisStreamsLambda", + "packageId": "Amazon.Constructs.AWS.KinesisStreamsLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-kinesis-streams-lambda", - "module": "aws_solutions_konstruk.aws_kinesis_streams_lambda" + "distName": "aws-solutions-constructs.aws-kinesis-streams-lambda", + "module": "aws_solutions_constructs.aws_kinesis_streams_lambda" } } }, "dependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -72,12 +72,12 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap similarity index 76% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap index 300bbac1a..6c176da95 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/__snapshots__/test.kinesisstreams-lambda.test.js.snap @@ -17,83 +17,13 @@ Object { }, }, "Resources": Object { - "testkinesisstreamslambdaEncryptionKey6CFF01F7": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "testkinesisstreamslambdaLambdaFunctionServiceRoleD083672F", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "testkinesisstreamslambdaKinesisStream76FFCAB1": Object { "Properties": Object { "RetentionPeriodHours": 24, "ShardCount": 1, "StreamEncryption": Object { "EncryptionType": "KMS", - "KeyId": Object { - "Fn::GetAtt": Array [ - "testkinesisstreamslambdaEncryptionKey6CFF01F7", - "Arn", - ], - }, + "KeyId": "alias/aws/kinesis", }, }, "Type": "AWS::Kinesis::Stream", @@ -298,16 +228,6 @@ Object { ], }, }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "testkinesisstreamslambdaEncryptionKey6CFF01F7", - "Arn", - ], - }, - }, ], "Version": "2012-10-17", }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json similarity index 76% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json index 74499c45d..4bace5dc4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.expected.json @@ -1,71 +1,6 @@ { "Description": "Integration Test for aws-kinesisstreams-lambda", "Resources": { - "testkslambdaEncryptionKey4161DDEB": { - "Type": "AWS::KMS::Key", - "Properties": { - "KeyPolicy": { - "Statement": [ - { - "Action": [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "testkslambdaLambdaFunctionServiceRole329F6464", - "Arn" - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "EnableKeyRotation": true - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "testkslambdaKinesisStreamE607D575": { "Type": "AWS::Kinesis::Stream", "Properties": { @@ -73,12 +8,7 @@ "RetentionPeriodHours": 24, "StreamEncryption": { "EncryptionType": "KMS", - "KeyId": { - "Fn::GetAtt": [ - "testkslambdaEncryptionKey4161DDEB", - "Arn" - ] - } + "KeyId": "alias/aws/kinesis" } } }, @@ -153,16 +83,6 @@ "Arn" ] } - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "testkslambdaEncryptionKey4161DDEB", - "Arn" - ] - } } ], "Version": "2012-10-17" diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.ts similarity index 98% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.ts index d04854a6d..141928d5c 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/integ.deployFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/integ.deployFunction.ts @@ -24,7 +24,6 @@ stack.templateOptions.description = 'Integration Test for aws-kinesisstreams-lam // Definitions const props: KinesisStreamsToLambdaProps = { deployLambda: true, - encryptionKeyProps: {}, kinesisStreamProps: {}, eventSourceProps: { startingPosition: lambda.StartingPosition.TRIM_HORIZON, diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts index 3496a455a..ba4ce4cc3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/test/test.kinesisstreams-lambda.test.ts @@ -41,11 +41,10 @@ test('Pattern minimal deployment', () => { // -------------------------------------------------------------- // Test getter methods // -------------------------------------------------------------- -test('Test getter methods', () => { +test('Test properties', () => { // Initial Setup const stack = new Stack(); const props: KinesisStreamsToLambdaProps = { - encryptionKeyProps: {}, kinesisStreamProps: {}, deployLambda: true, lambdaFunctionProps: { @@ -60,7 +59,9 @@ test('Test getter methods', () => { }; const app = new KinesisStreamsToLambda(stack, 'test-kinesis-streams-lambda', props); // Assertion 1 - expect(app.lambdaFunction()).toBeDefined(); + expect(app.lambdaFunction !== null); // Assertion 2 - expect(app.stream()).toBeDefined(); + expect(app.kinesisStream !== null); + // Assertion 3 + expect(app.kinesisStreamRole !== null); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.gitignore b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.npmignore b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md similarity index 63% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/README.md rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md index 94c615d1c..977a4bfcc 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-lambda-dynamodb/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_lambda_dynamodb`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-lambda-dynamodb`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_lambda_dynamodb`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-lambda-dynamodb`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.lambdadynamodb`| -This AWS Solutions Konstruk implements the AWS Lambda function and Amazon DynamoDB table with the least privileged permissions. +This AWS Solutions Construct implements the AWS Lambda function and Amazon DynamoDB table with the least privileged permissions. Here is a minimal deployable pattern definition: ``` javascript -const { LambdaToDynamoDBProps, LambdaToDynamoDB } = require('@aws-solutions-konstruk/aws-lambda-dynamodb'); +const { LambdaToDynamoDBProps, LambdaToDynamoDB } = require('@aws-solutions-constructs/aws-lambda-dynamodb'); const props: LambdaToDynamoDBProps = { deployLambda: true, @@ -68,8 +67,22 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| -|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| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|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| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon DynamoDB Table +* Set the billing mode for DynamoDB Table to On-Demand (Pay per request) +* Enable server-side encryption for DynamoDB Table using AWS managed KMS Key +* Creates a partition key called 'id' for DynamoDB Table +* Retain the Table when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/architecture.png b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/lib/index.ts similarity index 71% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/lib/index.ts index 9d822f260..82dedfabc 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/lib/index.ts @@ -13,9 +13,9 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as dynamodb from '@aws-cdk/aws-dynamodb'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; -import { overrideProps } from '@aws-solutions-konstruk/core'; +import { overrideProps } from '@aws-solutions-constructs/core'; /** * @summary The properties for the LambdaToDynamoDB Construct @@ -51,8 +51,8 @@ export interface LambdaToDynamoDBProps { } export class LambdaToDynamoDB extends Construct { - private fn: lambda.Function; - private table: dynamodb.Table; + public readonly lambdaFunction: lambda.Function; + public readonly dynamoTable: dynamodb.Table; /** * @summary Constructs a new instance of the LambdaToDynamoDB class. @@ -65,7 +65,7 @@ export class LambdaToDynamoDB extends Construct { constructor(scope: Construct, id: string, props: LambdaToDynamoDBProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -74,18 +74,18 @@ export class LambdaToDynamoDB extends Construct { // Set the default props for DynamoDB table if (props.dynamoTableProps) { const dynamoTableProps = overrideProps(defaults.DefaultTableProps, props.dynamoTableProps); - this.table = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', dynamoTableProps); } else { - this.table = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableProps); + this.dynamoTable = new dynamodb.Table(this, 'DynamoTable', defaults.DefaultTableProps); } - this.fn.addEnvironment('DDB_TABLE_NAME', this.table.tableName); + this.lambdaFunction.addEnvironment('DDB_TABLE_NAME', this.dynamoTable.tableName); - this.table.grantReadWriteData(this.fn.grantPrincipal); + this.dynamoTable.grantReadWriteData(this.lambdaFunction.grantPrincipal); // Conditional metadata for cfn_nag if (props.dynamoTableProps?.billingMode === dynamodb.BillingMode.PROVISIONED) { - const cfnTable: dynamodb.CfnTable = this.table.node.findChild('Resource') as dynamodb.CfnTable; + const cfnTable: dynamodb.CfnTable = this.dynamoTable.node.findChild('Resource') as dynamodb.CfnTable; cfnTable.cfnOptions.metadata = { cfn_nag: { rules_to_suppress: [{ @@ -96,25 +96,4 @@ export class LambdaToDynamoDB extends Construct { }; } } - - /** - * @summary Returns an instance of dynamodb.Table created by the construct. - * @returns {dynamodb.Table} Instance of dynamodb.Table created by the construct - * @since 0.8.0 - * @access public - */ - public dynamoTable(): dynamodb.Table { - return this.table; - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of lambda.Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/package.json b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/package.json similarity index 61% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/package.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/package.json index 004f9a249..8b159eaf3 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-lambda-dynamodb", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-lambda-dynamodb", + "version": "1.46.0", "description": "CDK Constructs for AWS Lambda to AWS DynamoDB integration.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb" }, "author": { "name": "Amazon Web Services", @@ -34,33 +34,33 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.lambdadynamodb", + "package": "software.amazon.awsconstructs.services.lambdadynamodb", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "lambdadynamodb" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.LambdaDynamodb", - "packageId": "Amazon.Konstruk.AWS.LambdaDynamodb", + "namespace": "Amazon.Constructs.AWS.LambdaDynamodb", + "packageId": "Amazon.Constructs.AWS.LambdaDynamodb", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-lambda-dynamodb", - "module": "aws_solutions_konstruk.aws_lambda_dynamodb" + "distName": "aws-solutions-constructs.aws-lambda-dynamodb", + "module": "aws_solutions_constructs.aws_lambda_dynamodb" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -70,10 +70,10 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/__snapshots__/lambda-dynamodb.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/__snapshots__/lambda-dynamodb.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/__snapshots__/lambda-dynamodb.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/__snapshots__/lambda-dynamodb.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.add-secondary-index.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.add-secondary-index.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.add-secondary-index.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.add-secondary-index.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.add-secondary-index.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.add-secondary-index.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.add-secondary-index.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.add-secondary-index.ts index 127960e45..1805a1c20 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.add-secondary-index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.add-secondary-index.ts @@ -37,6 +37,6 @@ const props: dynamodb.GlobalSecondaryIndexProps = { }, indexName: 'test_id2' }; -construct.dynamoTable().addGlobalSecondaryIndex(props); +construct.dynamoTable.addGlobalSecondaryIndex(props); app.synth(); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.set-billing-mode.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.set-billing-mode.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.set-billing-mode.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.set-billing-mode.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.set-billing-mode.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.set-billing-mode.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.set-billing-mode.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.set-billing-mode.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.use-existing-func.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.use-existing-func.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.use-existing-func.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.use-existing-func.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.use-existing-func.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.use-existing-func.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.use-existing-func.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.use-existing-func.ts index 203a9cef5..d254de838 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/integ.use-existing-func.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/integ.use-existing-func.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { LambdaToDynamoDB } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; const app = new App(); const stack = new Stack(app, 'test-lambda-dynamodb-stack'); diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts index 0fb55c051..03c9d799a 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts @@ -252,13 +252,13 @@ test('check iot lambda function role for deploy: false', () => { ] }); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: LambdaToDynamoDB = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.dynamoTable()).toBeInstanceOf(dynamodb.Table); + expect(construct.lambdaFunction !== null); + expect(construct.dynamoTable !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { const stack = new cdk.Stack(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-dynamodb/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.npmignore b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md similarity index 52% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/README.md rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md index 5ec92d388..f1d8fa6c5 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-lambda-elasticsearch-kibana/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_lambda_elasticsearch_kibana`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_lambda_elasticsearch_kibana`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-lambda-elasticsearch-kibana`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.lambdaelasticsearchkibana`| -This AWS Solutions Konstruk implements the AWS Lambda function and Amazon Elasticsearch Service with the least privileged permissions. +This AWS Solutions Construct implements the AWS Lambda function and Amazon Elasticsearch Service with the least privileged permissions. Here is a minimal deployable pattern definition: ``` javascript -const { LambdaToElasticSearchAndKibana } = require('@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana'); +const { LambdaToElasticSearchAndKibana } = require('@aws-solutions-constructs/aws-lambda-elasticsearch-kibana'); const lambdaProps: lambda.FunctionProps = { code: lambda.Code.asset(`${__dirname}/lambda`), @@ -70,12 +69,31 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|lambdaFunction()|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| -|userPool()|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| -|userPoolClient()|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| -|identityPool()|[`cognito.CfnIdentityPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnIdentityPool.html)|Returns an instance of cognito.CfnIdentityPool created by the construct| -|elasticsearchDomain()|[`elasticsearch.CfnDomain`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomain.html)|Returns an instance of elasticsearch.CfnDomain created by the construct| -|cloudwatchAlarms()|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| +|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| +|userPool|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct| +|userPoolClient|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct| +|identityPool|[`cognito.CfnIdentityPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnIdentityPool.html)|Returns an instance of cognito.CfnIdentityPool created by the construct| +|elasticsearchDomain|[`elasticsearch.CfnDomain`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomain.html)|Returns an instance of elasticsearch.CfnDomain created by the construct| +|cloudwatchAlarms|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon Cognito +* Set password policy for User Pools +* Enforce the advanced security mode for User Pools + +### Amazon Elasticsearch Service +* Deploy best practices CloudWatch Alarms for the Elasticsearch Domain +* Secure the Kibana dashboard access with Cognito User Pools +* Enable server-side encryption for Elasticsearch Domain using AWS managed KMS Key +* Enable node-to-node encryption for Elasticsearch Domain +* Configure the cluster for the Amazon ES domain ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/architecture.png b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/lib/index.ts similarity index 52% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/lib/index.ts index 17ba52ae8..314d1a27d 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/lib/index.ts @@ -14,7 +14,7 @@ import * as elasticsearch from '@aws-cdk/aws-elasticsearch'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cognito from '@aws-cdk/aws-cognito'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; import { Role } from '@aws-cdk/aws-iam'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; @@ -59,12 +59,12 @@ export interface LambdaToElasticSearchAndKibanaProps { } export class LambdaToElasticSearchAndKibana extends Construct { - private userpool: cognito.UserPool; - private identitypool: cognito.CfnIdentityPool; - private userpoolclient: cognito.UserPoolClient; - private elasticsearch: elasticsearch.CfnDomain; - private fn: lambda.Function; - private cwAlarms: cloudwatch.Alarm[]; + public readonly userPool: cognito.UserPool; + public readonly identityPool: cognito.CfnIdentityPool; + public readonly userPoolClient: cognito.UserPoolClient; + public readonly elasticsearchDomain: elasticsearch.CfnDomain; + public readonly lambdaFunction: lambda.Function; + public readonly cloudwatchAlarms: cloudwatch.Alarm[]; /** * @summary Constructs a new instance of the CognitoToApiGatewayToLambda class. @@ -77,95 +77,35 @@ export class LambdaToElasticSearchAndKibana extends Construct { constructor(scope: Construct, id: string, props: LambdaToElasticSearchAndKibanaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); // Find the lambda service Role ARN - const lambdaFunctionRoleARN = this.fn.role?.roleArn; + const lambdaFunctionRoleARN = this.lambdaFunction.role?.roleArn; - this.userpool = defaults.buildUserPool(this); - this.userpoolclient = defaults.buildUserPoolClient(this, this.userpool); - this.identitypool = defaults.buildIdentityPool(this, this.userpool, this.userpoolclient); + this.userPool = defaults.buildUserPool(this); + this.userPoolClient = defaults.buildUserPoolClient(this, this.userPool); + this.identityPool = defaults.buildIdentityPool(this, this.userPool, this.userPoolClient); const cognitoAuthorizedRole: Role = defaults.setupCognitoForElasticSearch(this, props.domainName, { - userpool: this.userpool, - identitypool: this.identitypool, - userpoolclient: this.userpoolclient + userpool: this.userPool, + identitypool: this.identityPool, + userpoolclient: this.userPoolClient }); - this.elasticsearch = defaults.buildElasticSearch(this, props.domainName, { - userpool: this.userpool, - identitypool: this.identitypool, + this.elasticsearchDomain = defaults.buildElasticSearch(this, props.domainName, { + userpool: this.userPool, + identitypool: this.identityPool, cognitoAuthorizedRoleARN: cognitoAuthorizedRole.roleArn, serviceRoleARN: lambdaFunctionRoleARN}, props.esDomainProps); // Add ES Domain to lambda envrionment variable - this.fn.addEnvironment('DOMAIN_ENDPOINT', this.elasticsearch.attrDomainEndpoint); + this.lambdaFunction.addEnvironment('DOMAIN_ENDPOINT', this.elasticsearchDomain.attrDomainEndpoint); // Deploy best practices CW Alarms for ES - this.cwAlarms = defaults.buildElasticSearchCWAlarms(this); - } - - /** - * @summary Returns an instance of lambda.Function created by the construct. - * @returns {lambda.Function} Instance of Function created by the construct - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of cognito.UserPool created by the construct. - * @returns {cognito.UserPool} Instance of UserPool created by the construct - * @since 0.8.0 - * @access public - */ - public userPool(): cognito.UserPool { - return this.userpool; - } - - /** - * @summary Returns an instance of cognito.UserPoolClient created by the construct. - * @returns {cognito.UserPoolClient} Instance of UserPoolClient created by the construct - * @since 0.8.0 - * @access public - */ - public userPoolClient(): cognito.UserPoolClient { - return this.userpoolclient; - } - - /** - * @summary Returns an instance of cognito.CfnIdentityPool created by the construct. - * @returns {cognito.CfnIdentityPool} Instance of CfnIdentityPool created by the construct - * @since 0.8.0 - * @access public - */ - public identityPool(): cognito.CfnIdentityPool { - return this.identitypool; - } - - /** - * @summary Returns an instance of elasticsearch.CfnDomain created by the construct. - * @returns {elasticsearch.CfnDomain} Instance of CfnDomain created by the construct - * @since 0.8.0 - * @access public - */ - public elasticsearchDomain(): elasticsearch.CfnDomain { - return this.elasticsearch; - } - - /** - * @summary Returns a list of cloudwatch.Alarm created by the construct. - * @returns {cloudwatch.Alarm[]} List of cloudwatch.Alarm created by the construct - * @since 0.8.0 - * @access public - */ - public cloudwatchAlarms(): cloudwatch.Alarm[] { - return this.cwAlarms; + this.cloudwatchAlarms = defaults.buildElasticSearchCWAlarms(this); } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/package.json b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/package.json similarity index 54% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/package.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/package.json index 30f802b3a..9be3878a7 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-lambda-elasticsearch-kibana", + "version": "1.46.0", "description": "CDK Constructs for AWS Lambda to AWS Elasticsearch with Kibana integration", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana" }, "author": { "name": "Amazon Web Services", @@ -34,36 +34,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.lambdaelasticsearchkibana", + "package": "software.amazon.awsconstructs.services.lambdaelasticsearchkibana", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "lambdaelasticsearchkibana" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.LambdaElasticsearchKibana", - "packageId": "Amazon.Konstruk.AWS.LambdaElasticsearchKibana", + "namespace": "Amazon.Constructs.AWS.LambdaElasticsearchKibana", + "packageId": "Amazon.Constructs.AWS.LambdaElasticsearchKibana", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-lambda-elasticsearch-kibana", - "module": "aws_solutions_konstruk.aws_lambda_elasticsearch_kibana" + "distName": "aws-solutions-constructs.aws-lambda-elasticsearch-kibana", + "module": "aws_solutions_constructs.aws_lambda_elasticsearch_kibana" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,13 +73,13 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap index bd735cd80..05def506b 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/__snapshots__/lambda-elasticsearch-kibana.test.js.snap @@ -230,6 +230,18 @@ Object { }, "testlambdaelasticsearchstackCognitoUserPool05D1387E": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, @@ -259,6 +271,24 @@ Object { }, "testlambdaelasticsearchstackCognitoUserPoolClient6610371B": Object { "Properties": Object { + "AllowedOAuthFlows": Array [ + "implicit", + "code", + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": Array [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin", + ], + "CallbackURLs": Array [ + "https://example.com", + ], + "SupportedIdentityProviders": Array [ + "COGNITO", + ], "UserPoolId": Object { "Ref": "testlambdaelasticsearchstackCognitoUserPool05D1387E", }, diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json index 227a829bc..43b80bb98 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.expected.json @@ -176,6 +176,18 @@ "testlambdaelasticsearchkibanaCognitoUserPool9537802B": { "Type": "AWS::Cognito::UserPool", "Properties": { + "AccountRecoverySetting": { + "RecoveryMechanisms": [ + { + "Name": "verified_phone_number", + "Priority": 1 + }, + { + "Name": "verified_email", + "Priority": 2 + } + ] + }, "AdminCreateUserConfig": { "AllowAdminCreateUserOnly": true }, @@ -207,7 +219,25 @@ "Properties": { "UserPoolId": { "Ref": "testlambdaelasticsearchkibanaCognitoUserPool9537802B" - } + }, + "AllowedOAuthFlows": [ + "implicit", + "code" + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin" + ], + "CallbackURLs": [ + "https://example.com" + ], + "SupportedIdentityProviders": [ + "COGNITO" + ] } }, "testlambdaelasticsearchkibanaCognitoIdentityPoolC48068F0": { @@ -233,7 +263,7 @@ "testlambdaelasticsearchkibanaUserPoolDomainB9BDF063": { "Type": "AWS::Cognito::UserPoolDomain", "Properties": { - "Domain": "test-domain1", + "Domain": "myconstructsdomain", "UserPoolId": { "Ref": "testlambdaelasticsearchkibanaCognitoUserPool9537802B" } @@ -286,7 +316,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/test-domain1/*" + ":domain/myconstructsdomain/*" ] ] } @@ -391,7 +421,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/test-domain1" + ":domain/myconstructsdomain" ] ] } @@ -459,7 +489,7 @@ { "Ref": "AWS::AccountId" }, - ":domain/test-domain1/*" + ":domain/myconstructsdomain/*" ] ] } @@ -482,7 +512,7 @@ "Ref": "testlambdaelasticsearchkibanaCognitoUserPool9537802B" } }, - "DomainName": "test-domain1", + "DomainName": "myconstructsdomain", "EBSOptions": { "EBSEnabled": true, "VolumeSize": 10 diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts index 77a79c83a..95ebacfb5 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/integ.no-arguments.ts @@ -29,7 +29,7 @@ const lambdaProps: lambda.FunctionProps = { new LambdaToElasticSearchAndKibana(stack, 'test-lambda-elasticsearch-kibana', { lambdaFunctionProps: lambdaProps, deployLambda: true, - domainName: 'test-domain1' + domainName: 'myconstructsdomain' }); // Synth diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts similarity index 80% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts index 78212c177..c0d0556b7 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/lambda-elasticsearch-kibana.test.ts @@ -16,8 +16,6 @@ import { LambdaToElasticSearchAndKibana, LambdaToElasticSearchAndKibanaProps } f import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from "@aws-cdk/core"; import '@aws-cdk/assert/jest'; -import { CfnDomain } from '@aws-cdk/aws-elasticsearch'; -import { CfnIdentityPool, UserPool, UserPoolClient } from '@aws-cdk/aws-cognito'; function deployNewFunc(stack: cdk.Stack) { const props: LambdaToElasticSearchAndKibanaProps = { @@ -57,17 +55,17 @@ test('check domain names', () => { }); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: LambdaToElasticSearchAndKibana = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.elasticsearchDomain()).toBeInstanceOf(CfnDomain); - expect(construct.identityPool()).toBeInstanceOf(CfnIdentityPool); - expect(construct.userPool()).toBeInstanceOf(UserPool); - expect(construct.userPoolClient()).toBeInstanceOf(UserPoolClient); - expect(construct.cloudwatchAlarms()).toHaveLength(9); + expect(construct.lambdaFunction !== null); + expect(construct.elasticsearchDomain !== null); + expect(construct.identityPool !== null); + expect(construct.userPool !== null); + expect(construct.userPoolClient !== null); + expect(construct.cloudwatchAlarms !== null); }); test('check exception for Missing existingObj from props for deploy = false', () => { diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.gitignore b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.npmignore b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md similarity index 64% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/README.md rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md index 219997e03..5cde61ea5 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-lambda-s3/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_lambda_s3`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-lambda-s3`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_lambda_s3`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-lambda-s3`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.lambdas3`| -This AWS Solutions Konstruk implements an AWS Lambda function connected to an Amazon S3 bucket. +This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon S3 bucket. Here is a minimal deployable pattern definition: ``` javascript -const { LambdaToS3 } = require('@aws-solutions-konstruk/aws-lambda-s3'); +const { LambdaToS3 } = require('@aws-solutions-constructs/aws-lambda-s3'); new LambdaToS3(stack, 'LambdaToS3Pattern', { deployLambda: true, @@ -65,9 +64,25 @@ _Parameters_ |bucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|Optional user provided props to override the default props for S3 Bucket| |bucketPermissions?|`string[]`|Optional bucket permissions to grant to the Lambda function. One or more of the following may be specified: `Delete`, `Put`, `Read`, `ReadWrite`, `Write`.| +## Pattern Properties -|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.| -|s3Bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the S3 bucket created by the pattern.| +|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.| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the S3 bucket created by the pattern.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/architecture.png b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/lib/index.ts similarity index 76% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/lib/index.ts index 091d15244..17b00ed92 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/lib/index.ts @@ -14,7 +14,7 @@ // Imports import * as lambda from '@aws-cdk/aws-lambda'; import * as s3 from '@aws-cdk/aws-s3'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -76,9 +76,8 @@ export interface LambdaToS3Props { * @summary The LambdaToS3 class. */ export class LambdaToS3 extends Construct { - // Private variables - private fn: lambda.Function; - private bucket: s3.Bucket; + public readonly lambdaFunction: lambda.Function; + public readonly s3Bucket: s3.Bucket; /** * @summary Constructs a new instance of the LambdaToS3 class. @@ -92,45 +91,45 @@ export class LambdaToS3 extends Construct { super(scope, id); // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); // Setup the S3 bucket - this.bucket = defaults.buildS3Bucket(this, { + this.s3Bucket = defaults.buildS3Bucket(this, { deployBucket: props.deployBucket, existingBucketObj: props.existingBucketObj, bucketProps: props.bucketProps }); // Configure environment variables - this.fn.addEnvironment('S3_BUCKET_NAME', this.bucket.bucketName); + this.lambdaFunction.addEnvironment('S3_BUCKET_NAME', this.s3Bucket.bucketName); // Add the requested or default bucket permissions if (props.hasOwnProperty('bucketPermissions') && props.bucketPermissions) { if (props.bucketPermissions.includes('Delete')) { - this.bucket.grantDelete(this.fn.grantPrincipal); + this.s3Bucket.grantDelete(this.lambdaFunction.grantPrincipal); } if (props.bucketPermissions.includes('Put')) { - this.bucket.grantPut(this.fn.grantPrincipal); + this.s3Bucket.grantPut(this.lambdaFunction.grantPrincipal); } if (props.bucketPermissions.includes('Read')) { - this.bucket.grantRead(this.fn.grantPrincipal); + this.s3Bucket.grantRead(this.lambdaFunction.grantPrincipal); } if (props.bucketPermissions.includes('ReadWrite')) { - this.bucket.grantReadWrite(this.fn.grantPrincipal); + this.s3Bucket.grantReadWrite(this.lambdaFunction.grantPrincipal); } if (props.bucketPermissions.includes('Write')) { - this.bucket.grantWrite(this.fn.grantPrincipal); + this.s3Bucket.grantWrite(this.lambdaFunction.grantPrincipal); } } else { - this.bucket.grantReadWrite(this.fn.grantPrincipal); + this.s3Bucket.grantReadWrite(this.lambdaFunction.grantPrincipal); } // Add appropriate metadata - const s3BucketResource = this.bucket.node.findChild('Resource') as s3.CfnBucket; + const s3BucketResource = this.s3Bucket.node.findChild('Resource') as s3.CfnBucket; s3BucketResource.cfnOptions.metadata = { cfn_nag: { rules_to_suppress: [{ @@ -140,24 +139,4 @@ export class LambdaToS3 extends Construct { } }; } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of the s3.Bucket created by the construct. - * @returns {s3.Bucket} Instance of the Bucket created by the construct. - * @since 0.8.0 - * @access public - */ - public s3Bucket(): s3.Bucket { - return this.bucket; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/package.json b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/package.json similarity index 62% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/package.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/package.json index 1e2e3d60c..277e06941 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-lambda-s3", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-lambda-s3", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an AWS Lambda function and an Amazon S3 bucket.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-lambda-s3" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-lambda-s3" }, "author": { "name": "Amazon Web Services", @@ -33,33 +33,33 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.lambdas3", + "package": "software.amazon.awsconstructs.services.lambdas3", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "lambdas3" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.LambdaS3", - "packageId": "Amazon.Konstruk.AWS.LambdaS3", + "namespace": "Amazon.Constructs.AWS.LambdaS3", + "packageId": "Amazon.Constructs.AWS.LambdaS3", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-lambda-s3", - "module": "aws_solutions_konstruk.aws_lambda_s3" + "distName": "aws-solutions-constructs.aws-lambda-s3", + "module": "aws_solutions_constructs.aws_lambda_s3" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -69,10 +69,10 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/__snapshots__/lambda-s3.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/__snapshots__/lambda-s3.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/__snapshots__/lambda-s3.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/__snapshots__/lambda-s3.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.deployFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.deployFunction.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.deployFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.deployFunction.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.deployFunction.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.deployFunction.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.deployFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.deployFunction.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.existingFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.existingFunction.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.existingFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.existingFunction.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.existingFunction.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.existingFunction.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.existingFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.existingFunction.ts index 738079769..2467e9150 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/integ.existingFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/integ.existingFunction.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { LambdaToS3, LambdaToS3Props } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // Setup const app = new App(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/lambda-s3.test.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/lambda-s3.test.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/lambda-s3.test.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/lambda-s3.test.ts index 324d3506a..cf2bffc42 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/lambda-s3.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/lambda-s3.test.ts @@ -160,7 +160,7 @@ test('Test deployment w/ s3 multiple permissions', () => { // -------------------------------------------------------------- // Test the getter methods // -------------------------------------------------------------- -test('Test the getter methods', () => { +test('Test the properties', () => { // Stack const stack = new Stack(); // Helper declaration @@ -174,11 +174,11 @@ test('Test the getter methods', () => { bucketPermissions: ['Write'] }); // Assertion 1 - const func = pattern.lambdaFunction(); - expect(func).toBeDefined(); + const func = pattern.lambdaFunction; + expect(func !== null); // Assertion 2 - const bucket = pattern.s3Bucket(); - expect(bucket).toBeDefined(); + const bucket = pattern.s3Bucket; + expect(bucket !== null); }); // -------------------------------------------------------------- diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-s3/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-lambda-s3/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.gitignore b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md similarity index 67% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/README.md rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md index bd54833d6..b40dec2f0 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-lambda-sns/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_lambda_sns`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-lambda-sns`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_lambda_sns`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-lambda-sns`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.lambdasns`| -This AWS Solutions Konstruk implements an AWS Lambda function connected to an Amazon SNS topic. +This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon SNS topic. Here is a minimal deployable pattern definition: ``` javascript -const { LambdaToSns } = require('@aws-solutions-konstruk/aws-lambda-sns'); +const { LambdaToSns } = require('@aws-solutions-constructs/aws-lambda-sns'); new LambdaToSns(stack, 'LambdaToSnsPattern', { deployLambda: true, @@ -68,8 +67,20 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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.| -|snsTopic()|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of the SNS topic created by the pattern.| +|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.| +|snsTopic|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of the SNS topic created by the pattern.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function + +### Amazon SNS Topic +* Configure least privilege access permissions for SNS Topic +* Enable server-side encryption forSNS Topic using Customer managed KMS Key ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/architecture.png b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/lib/index.ts similarity index 76% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/lib/index.ts index d7518d58d..d4abe8cc6 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/lib/index.ts @@ -15,7 +15,7 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as sns from '@aws-cdk/aws-sns'; import * as kms from '@aws-cdk/aws-kms'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; /** @@ -68,9 +68,8 @@ export interface LambdaToSnsProps { * @summary The LambdaToSns class. */ export class LambdaToSns extends Construct { - // Private variables - private fn: lambda.Function; - private topic: sns.Topic; + public readonly lambdaFunction: lambda.Function; + public readonly snsTopic: sns.Topic; /** * @summary Constructs a new instance of the LambdaToSns class. @@ -84,43 +83,23 @@ export class LambdaToSns extends Construct { super(scope, id); // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); // Setup the SNS topic - this.topic = defaults.buildTopic(this, { + this.snsTopic = defaults.buildTopic(this, { enableEncryption: props.enableEncryption, encryptionKey: props.encryptionKey }); // Configure environment variables - this.fn.addEnvironment('SNS_TOPIC_NAME', this.topic.topicName); - this.fn.addEnvironment('SNS_TOPIC_ARN', this.topic.topicArn); + this.lambdaFunction.addEnvironment('SNS_TOPIC_NAME', this.snsTopic.topicName); + this.lambdaFunction.addEnvironment('SNS_TOPIC_ARN', this.snsTopic.topicArn); // Add publishing permissions to the function - this.topic.grantPublish(this.fn.grantPrincipal); - } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of the sns.Topic created by the construct. - * @returns {sns.Topic} Instance of the Topic created by the construct. - * @since 0.8.0 - * @access public - */ - public snsTopic(): sns.Topic { - return this.topic; + this.snsTopic.grantPublish(this.lambdaFunction.grantPrincipal); } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/package.json b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/package.json similarity index 60% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/package.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/package.json index f68803794..ef8af8c5e 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-lambda-sns", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-lambda-sns", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an AWS Lambda function and an Amazon SNS topic.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-lambda-sns" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-lambda-sns" }, "author": { "name": "Amazon Web Services", @@ -33,34 +33,34 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.lambdasns", + "package": "software.amazon.awsconstructs.services.lambdasns", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "lambdasns" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.LambdaSns", - "packageId": "Amazon.Konstruk.AWS.LambdaSns", + "namespace": "Amazon.Constructs.AWS.LambdaSns", + "packageId": "Amazon.Constructs.AWS.LambdaSns", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-lambda-sns", - "module": "aws_solutions_konstruk.aws_lambda_sns" + "distName": "aws-solutions-constructs.aws-lambda-sns", + "module": "aws_solutions_constructs.aws_lambda_sns" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -70,11 +70,11 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/__snapshots__/lambda-sns.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/__snapshots__/lambda-sns.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/__snapshots__/lambda-sns.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/__snapshots__/lambda-sns.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.deployFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.deployFunction.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.deployFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.deployFunction.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.deployFunction.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.deployFunction.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.deployFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.deployFunction.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.existingFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.existingFunction.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.existingFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.existingFunction.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.existingFunction.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.existingFunction.ts similarity index 95% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.existingFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.existingFunction.ts index 575b481d7..37e5df975 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/integ.existingFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/integ.existingFunction.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { LambdaToSns, LambdaToSnsProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // Setup const app = new App(); diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/lambda-sns.test.ts b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/lambda-sns.test.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/lambda-sns.test.ts rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/lambda-sns.test.ts index e24fb0287..f472d7cab 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/lambda-sns.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/lambda-sns.test.ts @@ -130,7 +130,7 @@ test('Test deployment with imported encryption key', () => { // -------------------------------------------------------------- // Test the getter methods // -------------------------------------------------------------- -test('Test the getter methods', () => { +test('Test the properties', () => { // Stack const stack = new Stack(); // Helper declaration @@ -143,9 +143,9 @@ test('Test the getter methods', () => { } }); // Assertion 1 - const func = pattern.lambdaFunction(); - expect(func).toBeDefined(); + const func = pattern.lambdaFunction; + expect(func !== null); // Assertion 2 - const topic = pattern.snsTopic(); - expect(topic).toBeDefined(); + const topic = pattern.snsTopic; + expect(topic !== null); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-lambda-sns/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-lambda-sns/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md similarity index 69% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md index 188a26ea2..917403394 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-s3-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_s3_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-s3-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_s3_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-s3-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.s3lambda`| -This AWS Solutions Konstruk implements an Amazon S3 bucket connected to an AWS Lambda function. +This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS Lambda function. Here is a minimal deployable pattern definition: ``` javascript -const { S3ToLambdaProps, S3ToLambda } = require('@aws-solutions-konstruk/aws-s3-lambda'); +const { S3ToLambdaProps, S3ToLambda } = require('@aws-solutions-constructs/aws-s3-lambda'); const stack = new Stack(app, 'test-s3-lambda-stack'); @@ -73,8 +72,23 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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 construct| -|s3Bucket()|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the s3.Bucket created by the construct| +|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 construct| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the s3.Bucket created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/lib/index.ts similarity index 84% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/lib/index.ts index 5931974ee..ce684bdf4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/lib/index.ts @@ -15,7 +15,7 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as s3 from '@aws-cdk/aws-s3'; import { Construct, Stack } from '@aws-cdk/core'; import * as iam from '@aws-cdk/aws-iam'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { S3EventSourceProps, S3EventSource } from '@aws-cdk/aws-lambda-event-sources'; /** @@ -73,9 +73,8 @@ export interface S3ToLambdaProps { } export class S3ToLambda extends Construct { - // Private variables - private fn: lambda.Function; - private bucket: s3.Bucket; + public readonly lambdaFunction: lambda.Function; + public readonly s3Bucket: s3.Bucket; /** * @summary Constructs a new instance of the S3ToLambda class. * @param {cdk.App} scope - represents the scope for all the resources. @@ -87,20 +86,20 @@ export class S3ToLambda extends Construct { constructor(scope: Construct, id: string, props: S3ToLambdaProps) { super(scope, id); - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); - this.bucket = defaults.buildS3Bucket(this, { + this.s3Bucket = defaults.buildS3Bucket(this, { deployBucket: props.deployBucket, existingBucketObj: props.existingBucketObj, bucketProps: props.bucketProps }); // Create S3 trigger to invoke lambda function - this.fn.addEventSource(new S3EventSource(this.bucket, + this.lambdaFunction.addEventSource(new S3EventSource(this.s3Bucket, defaults.S3EventSourceProps(props.s3EventSourceProps))); this.addCfnNagSuppress(); @@ -108,7 +107,7 @@ export class S3ToLambda extends Construct { private addCfnNagSuppress() { // Extract the CfnBucket from the s3Bucket - const s3BucketResource = this.bucket.node.findChild('Resource') as s3.CfnBucket; + const s3BucketResource = this.s3Bucket.node.findChild('Resource') as s3.CfnBucket; s3BucketResource.cfnOptions.metadata = { cfn_nag: { @@ -149,24 +148,4 @@ export class S3ToLambda extends Construct { } }; } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of the s3.Bucket created by the construct. - * @returns {s3.Bucket} Instance of the Bucket created by the construct. - * @since 0.8.0 - * @access public - */ - public s3Bucket(): s3.Bucket { - return this.bucket; - } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/package.json similarity index 56% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/package.json index a0d85aad9..f609ad5c1 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-s3-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-s3-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS S3 to AWS Lambda integration", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-s3-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-s3-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,36 +34,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.s3lambda", + "package": "software.amazon.awsconstructs.services.s3lambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "s3lambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.S3Lambda", - "packageId": "Amazon.Konstruk.AWS.S3Lambda", + "namespace": "Amazon.Constructs.AWS.S3Lambda", + "packageId": "Amazon.Constructs.AWS.S3Lambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-s3-lambda", - "module": "aws_solutions_konstruk.aws_s3_lambda" + "distName": "aws-solutions-constructs.aws-s3-lambda", + "module": "aws_solutions_constructs.aws_s3_lambda" } } }, "dependencies": { - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/aws-s3-notifications": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-s3-notifications": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,13 +73,13 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-s3-notifications": "~1.40.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-s3-notifications": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/__snapshots__/s3-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/__snapshots__/s3-lambda.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/__snapshots__/s3-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/__snapshots__/s3-lambda.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.existing-s3-bucket.ts b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.existing-s3-bucket.ts rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.ts index d4cfa5665..8b906cdf8 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.existing-s3-bucket.ts +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.ts @@ -16,7 +16,7 @@ import { App, Stack } from "@aws-cdk/core"; import { S3ToLambda, S3ToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; import * as s3 from '@aws-cdk/aws-s3'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; const app = new App(); // Empty arguments diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/s3-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/s3-lambda.test.ts similarity index 87% rename from source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/s3-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/s3-lambda.test.ts index 3533808a8..6967e69f8 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-s3-lambda/test/s3-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/s3-lambda.test.ts @@ -14,7 +14,6 @@ import { SynthUtils } from '@aws-cdk/assert'; import { S3ToLambda, S3ToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from "@aws-cdk/core"; import '@aws-cdk/assert/jest'; @@ -37,11 +36,11 @@ test('snapshot test S3ToLambda default params', () => { expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: S3ToLambda = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.s3Bucket()).toBeInstanceOf(s3.Bucket); + expect(construct.lambdaFunction !== null); + expect(construct.s3Bucket !== null); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.eslintignore rename to source/patterns/@aws-solutions-constructs/aws-s3-step-function/.eslintignore diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/.gitignore b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/.gitignore new file mode 100644 index 000000000..8626f2274 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/.gitignore @@ -0,0 +1,16 @@ +lib/*.js +test/*.js +!test/lambda/* +*.js.map +*.d.ts +node_modules +*.generated.ts +dist +.jsii + +.LAST_BUILD +.nyc_output +coverage +.nycrc +.LAST_PACKAGE +*.snk \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-s3-step-function/.npmignore diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/README.md b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/README.md new file mode 100644 index 000000000..f8934f014 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/README.md @@ -0,0 +1,100 @@ +# aws-s3-step-function module + + +--- + +![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) + +> All classes are under active development and subject to non-backward compatible changes or removal in any +> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. +> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. + +--- + + +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| +|:-------------|:-------------| +
+ +| **Language** | **Package** | +|:-------------|-----------------| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_s3_step_function`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-s3-step-function`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.s3stepfunction`| + +This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS Step Function. + +Here is a minimal deployable pattern definition: + +``` javascript +const { S3ToStepFunction, S3ToStepFunctionProps } = require('@aws-solutions-constructs/aws-s3-step-function'); + +const startState = new stepfunctions.Pass(stack, 'StartState'); + +const props: S3ToStepFunctionProps = { + stateMachineProps: { + definition: startState + } +}; + +new S3ToStepFunction(stack, 'test-s3-step-function-stack', props); +``` + +## Initializer + +``` text +new S3ToStepFunction(scope: Construct, id: string, props: S3ToStepFunctionProps); +``` + +_Parameters_ + +* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) +* id `string` +* props [`S3ToStepFunctionProps`](#pattern-construct-props) + +## Pattern Construct Props + +| **Name** | **Type** | **Description** | +|:-------------|:----------------|-----------------| +|deployBucket?|`boolean`|Whether to create a S3 Bucket or use an existing S3 Bucket| +|existingBucketObj?|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Existing instance of S3 Bucket object| +|bucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|Optional user provided props to override the default props for S3 Bucket| +|stateMachineProps|[`sfn.StateMachineProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachineProps.html)|Optional user provided props to override the default props for sfn.StateMachine| +|eventRuleProps?|[`events.RuleProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)|Optional user provided eventRuleProps to override the defaults| +|deployCloudTrail?|`boolean`|Whether to deploy a Trail in AWS CloudTrail to log API events in Amazon S3| + +## Pattern Properties + +| **Name** | **Type** | **Description** | +|:-------------|:----------------|-----------------| +|stateMachine|[`sfn.StateMachine`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachine.html)|Returns an instance of sfn.StateMachine created by the construct| +|cloudwatchAlarms|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct| +|s3Bucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the s3.Bucket created by the construct| +|cloudtrail|[`cloudtrail.Trail`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudtrail.Trail.html)|Returns an instance of the cloudtrail.Trail created by the construct| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon S3 Bucket +* Configure Access logging for S3 Bucket +* Enable server-side encryption for S3 Bucket using AWS managed KMS Key +* Turn on the versioning for S3 Bucket +* Don't allow public access for S3 Bucket +* Retain the S3 Bucket when deleting the CloudFormation stack + +### AWS CloudTrail +* Configure a Trail in AWS CloudTrail to log API events in Amazon S3 related to the Bucket created by the Construct + +### Amazon CloudWatch Events Rule +* Grant least privilege permissions to CloudWatch Events to trigger the Lambda Function + +### AWS Step Function +* Enable CloudWatch logging for API Gateway +* Deploy best practices CloudWatch Alarms for the Step Function + +## Architecture +![Architecture Diagram](architecture.png) + +*** +© Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/architecture.png b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/architecture.png new file mode 100644 index 000000000..da37b98d6 Binary files /dev/null and b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/architecture.png differ diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/lib/index.ts new file mode 100644 index 000000000..4fc83e00f --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/lib/index.ts @@ -0,0 +1,160 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as s3 from '@aws-cdk/aws-s3'; +import * as defaults from '@aws-solutions-constructs/core'; +import { EventsRuleToStepFunction } from '@aws-solutions-constructs/aws-events-rule-step-function'; +import { Construct } from '@aws-cdk/core'; +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; +import * as cloudtrail from '@aws-cdk/aws-cloudtrail'; +import * as events from '@aws-cdk/aws-events'; + +/** + * @summary The properties for the S3ToStepFunction Construct + */ +export interface S3ToStepFunctionProps { + /** + * Whether to create a S3 Bucket or use an existing S3 Bucket. + * If set to false, you must provide S3 Bucket as `existingBucketObj` + * + * @default - true + */ + readonly deployBucket?: boolean, + /** + * Existing instance of S3 Bucket object. + * If `deployBucket` is set to false only then this property is required + * + * @default - None + */ + readonly existingBucketObj?: s3.Bucket, + /** + * Optional user provided props to override the default props. + * If `deploy` is set to true only then this property is required + * + * @default - Default props are used + */ + readonly bucketProps?: s3.BucketProps, + /** + * User provided StateMachineProps to override the defaults + * + * @default - None + */ + readonly stateMachineProps: sfn.StateMachineProps, + /** + * User provided eventRuleProps to override the defaults + * + * @default - None + */ + readonly eventRuleProps?: events.RuleProps; + /** + * Whether to deploy a Trail in AWS CloudTrail to log API events in Amazon S3 + * + * @default - true + */ + readonly deployCloudTrail?: boolean +} + +export class S3ToStepFunction extends Construct { + public readonly stateMachine: sfn.StateMachine; + public readonly s3Bucket: s3.Bucket; + public readonly cloudwatchAlarms: cloudwatch.Alarm[]; + public readonly cloudtrail: cloudtrail.Trail | undefined; + + /** + * @summary Constructs a new instance of the S3ToStepFunction class. + * @param {cdk.App} scope - represents the scope for all the resources. + * @param {string} id - this is a a scope-unique id. + * @param {S3ToStepFunctionProps} props - user provided props for the construct + * @since 0.9.0 + * @access public + */ + constructor(scope: Construct, id: string, props: S3ToStepFunctionProps) { + super(scope, id); + + this.s3Bucket = defaults.buildS3Bucket(this, { + deployBucket: props.deployBucket, + existingBucketObj: props.existingBucketObj, + bucketProps: props.bucketProps + }); + + this.addCfnNagSuppress(this.s3Bucket); + + if (!props.hasOwnProperty('deployCloudTrail') || props.deployCloudTrail === true) { + const trailBucket = defaults.buildS3Bucket(this, { + deployBucket: true + }, 'CloudTrail'); + + this.addCfnNagSuppress(trailBucket); + + this.cloudtrail = new cloudtrail.Trail(this, 'S3EventsTrail', { + bucket: trailBucket + }); + + this.cloudtrail.addS3EventSelector([{ + bucket: this.s3Bucket + }], { + readWriteType: cloudtrail.ReadWriteType.ALL, + includeManagementEvents: false + }); + } + + let _eventRuleProps = {}; + if (props.eventRuleProps) { + _eventRuleProps = props.eventRuleProps; + } else { + // By default the CW Events Rule will filter any 's3:PutObject' events for the S3 Bucket + _eventRuleProps = { + eventPattern: { + source: ['aws.s3'], + detailType: ['AWS API Call via CloudTrail'], + detail: { + eventSource: [ + "s3.amazonaws.com" + ], + eventName: [ + "PutObject" + ], + requestParameters: { + bucketName: [ + this.s3Bucket.bucketName + ] + } + } + } + }; + } + + const eventsRuleToStepFunction = new EventsRuleToStepFunction(this, 'test-events-rule-step-function-stack', { + stateMachineProps: props.stateMachineProps, + eventRuleProps: _eventRuleProps + }); + + this.stateMachine = eventsRuleToStepFunction.stateMachine; + this.cloudwatchAlarms = eventsRuleToStepFunction.cloudwatchAlarms; + } + + private addCfnNagSuppress(bucket: s3.Bucket) { + // Extract the CfnBucket from the s3Bucket + const s3BucketResource = bucket.node.findChild('Resource') as s3.CfnBucket; + + s3BucketResource.cfnOptions.metadata = { + cfn_nag: { + rules_to_suppress: [{ + id: 'W51', + reason: `This S3 bucket Bucket does not need a bucket policy` + }] + } + }; + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/package.json b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/package.json new file mode 100644 index 000000000..abd6243c0 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/package.json @@ -0,0 +1,93 @@ +{ + "name": "@aws-solutions-constructs/aws-s3-step-function", + "version": "1.46.0", + "description": "CDK Constructs for AWS S3 to AWS Step Function integration", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-s3-step-function" + }, + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "scripts": { + "build": "tsc -b .", + "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", + "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", + "test": "jest --coverage", + "clean": "tsc -b --clean", + "watch": "tsc -b -w", + "integ": "cdk-integ", + "integ-no-clean": "cdk-integ --no-clean", + "integ-assert": "cdk-integ-assert", + "jsii": "jsii", + "jsii-pacmak": "jsii-pacmak", + "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", + "snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" + }, + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awsconstructs.services.s3stepfunction", + "maven": { + "groupId": "software.amazon.awsconstructs", + "artifactId": "s3stepfunction" + } + }, + "dotnet": { + "namespace": "Amazon.Constructs.AWS.S3StepFunction", + "packageId": "Amazon.Constructs.AWS.S3StepFunction", + "signAssembly": true, + "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" + }, + "python": { + "distName": "aws-solutions-constructs.aws-s3-step-function", + "module": "aws_solutions_constructs.aws_s3_step_function" + } + } + }, + "dependencies": { + "@aws-cdk/aws-stepfunctions": "~1.46.0", + "@aws-cdk/aws-stepfunctions-tasks": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-cdk/aws-cloudtrail": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-events-rule-step-function": "~1.46.0", + "constructs": "^3.0.2" + }, + "devDependencies": { + "@aws-cdk/assert": "~1.46.0", + "@types/jest": "^24.0.23", + "@types/node": "^10.3.0" + }, + "jest": { + "moduleFileExtensions": [ + "js" + ] + }, + "peerDependencies": { + "@aws-cdk/aws-stepfunctions": "~1.46.0", + "@aws-cdk/aws-stepfunctions-tasks": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-cdk/aws-cloudtrail": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-solutions-constructs/aws-events-rule-step-function": "~1.46.0", + "constructs": "^3.0.2" + } +} diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/__snapshots__/s3-step-function.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/__snapshots__/s3-step-function.test.js.snap new file mode 100644 index 000000000..8a6d56d65 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/__snapshots__/s3-step-function.test.js.snap @@ -0,0 +1,537 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot test S3ToStepFunction default params 1`] = ` +Object { + "Resources": Object { + "tests3stepfunctionCloudTrailS3Bucket826F62C0": Object { + "DeletionPolicy": "Retain", + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy", + }, + ], + }, + }, + "Properties": Object { + "BucketEncryption": Object { + "ServerSideEncryptionConfiguration": Array [ + Object { + "ServerSideEncryptionByDefault": Object { + "SSEAlgorithm": "AES256", + }, + }, + ], + }, + "LoggingConfiguration": Object { + "DestinationBucketName": Object { + "Ref": "tests3stepfunctionCloudTrailS3LoggingBucket4FA5C122", + }, + }, + "PublicAccessBlockConfiguration": Object { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true, + }, + "VersioningConfiguration": Object { + "Status": "Enabled", + }, + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "tests3stepfunctionCloudTrailS3BucketPolicyA41AE459": Object { + "Properties": Object { + "Bucket": Object { + "Ref": "tests3stepfunctionCloudTrailS3Bucket826F62C0", + }, + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "s3:GetBucketAcl", + "Effect": "Allow", + "Principal": Object { + "Service": "cloudtrail.amazonaws.com", + }, + "Resource": Object { + "Fn::GetAtt": Array [ + "tests3stepfunctionCloudTrailS3Bucket826F62C0", + "Arn", + ], + }, + }, + Object { + "Action": "s3:PutObject", + "Condition": Object { + "StringEquals": Object { + "s3:x-amz-acl": "bucket-owner-full-control", + }, + }, + "Effect": "Allow", + "Principal": Object { + "Service": "cloudtrail.amazonaws.com", + }, + "Resource": Object { + "Fn::Join": Array [ + "", + Array [ + Object { + "Fn::GetAtt": Array [ + "tests3stepfunctionCloudTrailS3Bucket826F62C0", + "Arn", + ], + }, + "/AWSLogs/", + Object { + "Ref": "AWS::AccountId", + }, + "/*", + ], + ], + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::S3::BucketPolicy", + }, + "tests3stepfunctionCloudTrailS3LoggingBucket4FA5C122": Object { + "DeletionPolicy": "Retain", + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W35", + "reason": "This S3 bucket is used as the access logging bucket for another bucket", + }, + Object { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy", + }, + ], + }, + }, + "Properties": Object { + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": Object { + "ServerSideEncryptionConfiguration": Array [ + Object { + "ServerSideEncryptionByDefault": Object { + "SSEAlgorithm": "AES256", + }, + }, + ], + }, + "PublicAccessBlockConfiguration": Object { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true, + }, + "VersioningConfiguration": Object { + "Status": "Enabled", + }, + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "tests3stepfunctionS3Bucket57D6600C": Object { + "DeletionPolicy": "Retain", + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy", + }, + ], + }, + }, + "Properties": Object { + "BucketEncryption": Object { + "ServerSideEncryptionConfiguration": Array [ + Object { + "ServerSideEncryptionByDefault": Object { + "SSEAlgorithm": "AES256", + }, + }, + ], + }, + "LoggingConfiguration": Object { + "DestinationBucketName": Object { + "Ref": "tests3stepfunctionS3LoggingBucketF58651AD", + }, + }, + "PublicAccessBlockConfiguration": Object { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true, + }, + "VersioningConfiguration": Object { + "Status": "Enabled", + }, + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "tests3stepfunctionS3EventsTrail4ECD93D3": Object { + "DependsOn": Array [ + "tests3stepfunctionCloudTrailS3BucketPolicyA41AE459", + ], + "Properties": Object { + "EnableLogFileValidation": true, + "EventSelectors": Array [ + Object { + "DataResources": Array [ + Object { + "Type": "AWS::S3::Object", + "Values": Array [ + Object { + "Fn::Join": Array [ + "", + Array [ + Object { + "Fn::GetAtt": Array [ + "tests3stepfunctionS3Bucket57D6600C", + "Arn", + ], + }, + "/", + ], + ], + }, + ], + }, + ], + "IncludeManagementEvents": false, + "ReadWriteType": "All", + }, + ], + "IncludeGlobalServiceEvents": true, + "IsLogging": true, + "IsMultiRegionTrail": true, + "S3BucketName": Object { + "Ref": "tests3stepfunctionCloudTrailS3Bucket826F62C0", + }, + }, + "Type": "AWS::CloudTrail::Trail", + }, + "tests3stepfunctionS3LoggingBucketF58651AD": Object { + "DeletionPolicy": "Retain", + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W35", + "reason": "This S3 bucket is used as the access logging bucket for another bucket", + }, + Object { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy", + }, + ], + }, + }, + "Properties": Object { + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": Object { + "ServerSideEncryptionConfiguration": Array [ + Object { + "ServerSideEncryptionByDefault": Object { + "SSEAlgorithm": "AES256", + }, + }, + ], + }, + "PublicAccessBlockConfiguration": Object { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true, + }, + "VersioningConfiguration": Object { + "Status": "Enabled", + }, + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackEventsRule05BF80D3": Object { + "Properties": Object { + "EventPattern": Object { + "detail": Object { + "eventName": Array [ + "PutObject", + ], + "eventSource": Array [ + "s3.amazonaws.com", + ], + "requestParameters": Object { + "bucketName": Array [ + Object { + "Ref": "tests3stepfunctionS3Bucket57D6600C", + }, + ], + }, + }, + "detail-type": Array [ + "AWS API Call via CloudTrail", + ], + "source": Array [ + "aws.s3", + ], + }, + "State": "ENABLED", + "Targets": Array [ + Object { + "Arn": Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF", + }, + "Id": "Target0", + "RoleArn": Object { + "Fn::GetAtt": Array [ + "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleF447A174", + "Arn", + ], + }, + }, + ], + }, + "Type": "AWS::Events::Rule", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleDefaultPolicy9B31B120": Object { + "Properties": Object { + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF", + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleDefaultPolicy9B31B120", + "Roles": Array [ + Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleF447A174", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleF447A174": Object { + "Properties": Object { + "AssumeRolePolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": Object { + "Service": "events.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackExecutionAbortedAlarm2467E717": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that aborted exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionsAborted", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Maximum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackExecutionFailedAlarmABAAA96A": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that failed exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionsFailed", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackExecutionThrottledAlarm1D666C22": Object { + "Properties": Object { + "AlarmDescription": "Alarm for the number of executions that throttled exceeded the threshold of 1. ", + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "Dimensions": Array [ + Object { + "Name": "StateMachineArn", + "Value": Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF", + }, + }, + ], + "EvaluationPeriods": 1, + "MetricName": "ExecutionThrottled", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1, + }, + "Type": "AWS::CloudWatch::Alarm", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF": Object { + "DependsOn": Array [ + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRoleDefaultPolicy4B8FDFDA", + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRole9C9F9AAC", + ], + "Properties": Object { + "DefinitionString": "{\\"StartAt\\":\\"StartState\\",\\"States\\":{\\"StartState\\":{\\"Type\\":\\"Pass\\",\\"End\\":true}}}", + "LoggingConfiguration": Object { + "Destinations": Array [ + Object { + "CloudWatchLogsLogGroup": Object { + "LogGroupArn": Object { + "Fn::GetAtt": Array [ + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineLogGroupDA892B18", + "Arn", + ], + }, + }, + }, + ], + "Level": "ERROR", + }, + "RoleArn": Object { + "Fn::GetAtt": Array [ + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRole9C9F9AAC", + "Arn", + ], + }, + }, + "Type": "AWS::StepFunctions::StateMachine", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineLogGroupDA892B18": Object { + "DeletionPolicy": "Retain", + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRole9C9F9AAC": Object { + "Properties": Object { + "AssumeRolePolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": Object { + "Service": Object { + "Fn::Join": Array [ + "", + Array [ + "states.", + Object { + "Ref": "AWS::Region", + }, + ".amazonaws.com", + ], + ], + }, + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRoleDefaultPolicy4B8FDFDA": Object { + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations", + }, + ], + }, + }, + "Properties": Object { + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": Array [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + ], + "Effect": "Allow", + "Resource": "*", + }, + Object { + "Action": Array [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups", + ], + "Effect": "Allow", + "Resource": Object { + "Fn::Join": Array [ + "", + Array [ + "arn:aws:logs:", + Object { + "Ref": "AWS::Region", + }, + ":", + Object { + "Ref": "AWS::AccountId", + }, + ":*", + ], + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRoleDefaultPolicy4B8FDFDA", + "Roles": Array [ + Object { + "Ref": "tests3stepfunctiontesteventsrulestepfunctionstackStateMachineRole9C9F9AAC", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + }, +} +`; diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.expected.json b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.expected.json new file mode 100644 index 000000000..29ef32f0f --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.expected.json @@ -0,0 +1,533 @@ +{ + "Resources": { + "tests3stepfunctionstackS3LoggingBucket740A14C5": { + "Type": "AWS::S3::Bucket", + "Properties": { + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W35", + "reason": "This S3 bucket is used as the access logging bucket for another bucket" + }, + { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy" + } + ] + } + } + }, + "tests3stepfunctionstackS3Bucket8CC704E9": { + "Type": "AWS::S3::Bucket", + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "LoggingConfiguration": { + "DestinationBucketName": { + "Ref": "tests3stepfunctionstackS3LoggingBucket740A14C5" + } + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy" + } + ] + } + } + }, + "tests3stepfunctionstackCloudTrailS3LoggingBucketC8E8D35B": { + "Type": "AWS::S3::Bucket", + "Properties": { + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W35", + "reason": "This S3 bucket is used as the access logging bucket for another bucket" + }, + { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy" + } + ] + } + } + }, + "tests3stepfunctionstackCloudTrailS3Bucket9CD2A45F": { + "Type": "AWS::S3::Bucket", + "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "LoggingConfiguration": { + "DestinationBucketName": { + "Ref": "tests3stepfunctionstackCloudTrailS3LoggingBucketC8E8D35B" + } + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + }, + "VersioningConfiguration": { + "Status": "Enabled" + } + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain", + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W51", + "reason": "This S3 bucket Bucket does not need a bucket policy" + } + ] + } + } + }, + "tests3stepfunctionstackCloudTrailS3BucketPolicyE88DD0A5": { + "Type": "AWS::S3::BucketPolicy", + "Properties": { + "Bucket": { + "Ref": "tests3stepfunctionstackCloudTrailS3Bucket9CD2A45F" + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:GetBucketAcl", + "Effect": "Allow", + "Principal": { + "Service": "cloudtrail.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "tests3stepfunctionstackCloudTrailS3Bucket9CD2A45F", + "Arn" + ] + } + }, + { + "Action": "s3:PutObject", + "Condition": { + "StringEquals": { + "s3:x-amz-acl": "bucket-owner-full-control" + } + }, + "Effect": "Allow", + "Principal": { + "Service": "cloudtrail.amazonaws.com" + }, + "Resource": { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "tests3stepfunctionstackCloudTrailS3Bucket9CD2A45F", + "Arn" + ] + }, + "/AWSLogs/", + { + "Ref": "AWS::AccountId" + }, + "/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + } + } + }, + "tests3stepfunctionstackS3EventsTrailE9BE674D": { + "Type": "AWS::CloudTrail::Trail", + "Properties": { + "IsLogging": true, + "S3BucketName": { + "Ref": "tests3stepfunctionstackCloudTrailS3Bucket9CD2A45F" + }, + "EnableLogFileValidation": true, + "EventSelectors": [ + { + "DataResources": [ + { + "Type": "AWS::S3::Object", + "Values": [ + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "tests3stepfunctionstackS3Bucket8CC704E9", + "Arn" + ] + }, + "/" + ] + ] + } + ] + } + ], + "IncludeManagementEvents": false, + "ReadWriteType": "All" + } + ], + "IncludeGlobalServiceEvents": true, + "IsMultiRegionTrail": true + }, + "DependsOn": [ + "tests3stepfunctionstackCloudTrailS3BucketPolicyE88DD0A5" + ] + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineLogGroupB72DF7A1": { + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleC204E28A": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleDefaultPolicyCF5075D2": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries" + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:aws:logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleDefaultPolicyCF5075D2", + "Roles": [ + { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleC204E28A" + } + ] + }, + "Metadata": { + "cfn_nag": { + "rules_to_suppress": [ + { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations" + } + ] + } + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": "{\"StartAt\":\"StartState\",\"States\":{\"StartState\":{\"Type\":\"Pass\",\"End\":true}}}", + "RoleArn": { + "Fn::GetAtt": [ + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleC204E28A", + "Arn" + ] + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineLogGroupB72DF7A1", + "Arn" + ] + } + } + } + ], + "Level": "ERROR" + } + }, + "DependsOn": [ + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleDefaultPolicyCF5075D2", + "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachineRoleC204E28A" + ] + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRuleRole7F5DCB98": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRuleRoleDefaultPolicy7B926713": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRuleRoleDefaultPolicy7B926713", + "Roles": [ + { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRuleRole7F5DCB98" + } + ] + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRule617230F2": { + "Type": "AWS::Events::Rule", + "Properties": { + "EventPattern": { + "source": [ + "aws.s3" + ], + "detail-type": [ + "AWS API Call via CloudTrail" + ], + "detail": { + "eventSource": [ + "s3.amazonaws.com" + ], + "eventName": [ + "PutObject" + ], + "requestParameters": { + "bucketName": [ + { + "Ref": "tests3stepfunctionstackS3Bucket8CC704E9" + } + ] + } + } + }, + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C" + }, + "Id": "Target0", + "RoleArn": { + "Fn::GetAtt": [ + "tests3stepfunctionstacktesteventsrulestepfunctionstackEventsRuleRole7F5DCB98", + "Arn" + ] + } + } + ] + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackExecutionFailedAlarmFB9B3517": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that failed exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C" + } + } + ], + "MetricName": "ExecutionsFailed", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackExecutionThrottledAlarmF000208D": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that throttled exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C" + } + } + ], + "MetricName": "ExecutionThrottled", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Sum", + "Threshold": 1 + } + }, + "tests3stepfunctionstacktesteventsrulestepfunctionstackExecutionAbortedAlarmE5C0507E": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "EvaluationPeriods": 1, + "AlarmDescription": "Alarm for the number of executions that aborted exceeded the threshold of 1. ", + "Dimensions": [ + { + "Name": "StateMachineArn", + "Value": { + "Ref": "tests3stepfunctionstacktesteventsrulestepfunctionstackStateMachine03BA781C" + } + } + ], + "MetricName": "ExecutionsAborted", + "Namespace": "AWS/States", + "Period": 300, + "Statistic": "Maximum", + "Threshold": 1 + } + } + } +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.ts b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.ts new file mode 100644 index 000000000..b2f816329 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/integ.s3-step-function-no-argument.ts @@ -0,0 +1,31 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +/// !cdk-integ * +import { App, Stack } from "@aws-cdk/core"; +import { S3ToStepFunction, S3ToStepFunctionProps } from "../lib"; +import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; + +const app = new App(); +const stack = new Stack(app, 'test-s3-step-function-stack'); + +const startState = new stepfunctions.Pass(stack, 'StartState'); + +const props: S3ToStepFunctionProps = { + stateMachineProps: { + definition: startState + } +}; + +new S3ToStepFunction(stack, 'test-s3-step-function-stack', props); +app.synth(); diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/lambda/index.js new file mode 100644 index 000000000..4b3640c1e --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/lambda/index.js @@ -0,0 +1,10 @@ +console.log('Loading function'); + +exports.handler = async (event, context) => { + console.log('Received event:', JSON.stringify(event, null, 2)); +    return { +      statusCode: 200, +      headers: { 'Content-Type': 'text/plain' }, +      body: `Hello from Project Vesper! You've hit ${event.path}\n` +    }; +}; \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/s3-step-function.test.ts b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/s3-step-function.test.ts new file mode 100644 index 000000000..48ee58186 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/test/s3-step-function.test.ts @@ -0,0 +1,143 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import { SynthUtils } from '@aws-cdk/assert'; +import { S3ToStepFunction, S3ToStepFunctionProps } from '../lib/index'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import '@aws-cdk/assert/jest'; +import * as cdk from '@aws-cdk/core'; +import { Bucket } from '@aws-cdk/aws-s3'; + +function deployNewStateMachine(stack: cdk.Stack) { + + const startState = new sfn.Pass(stack, 'StartState'); + + const props: S3ToStepFunctionProps = { + stateMachineProps: { + definition: startState + } + }; + + return new S3ToStepFunction(stack, 'test-s3-step-function', props); +} + +test('snapshot test S3ToStepFunction default params', () => { + const stack = new cdk.Stack(); + deployNewStateMachine(stack); + expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); +}); + +test('check deployCloudTrail = false', () => { + const stack = new cdk.Stack(); + + const startState = new sfn.Pass(stack, 'StartState'); + + const props: S3ToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + deployCloudTrail: false + }; + + const construct = new S3ToStepFunction(stack, 'test-s3-step-function', props); + + expect(construct.cloudtrail === undefined); +}); + +test('override eventRuleProps', () => { + const stack = new cdk.Stack(); + + const mybucket = new Bucket(stack, 'mybucket'); + const startState = new sfn.Pass(stack, 'StartState'); + + const props: S3ToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + deployBucket: false, + existingBucketObj: mybucket, + eventRuleProps: { + eventPattern: { + source: ['aws.s3'], + detailType: ['AWS API Call via CloudTrail'], + detail: { + eventSource: [ + "s3.amazonaws.com" + ], + eventName: [ + "GetObject" + ], + requestParameters: { + bucketName: [ + mybucket.bucketName + ] + } + } + } + } + }; + + new S3ToStepFunction(stack, 'test-s3-step-function', props); + + expect(stack).toHaveResource('AWS::Events::Rule', { + EventPattern: { + "source": [ + "aws.s3" + ], + "detail-type": [ + "AWS API Call via CloudTrail" + ], + "detail": { + eventSource: [ + "s3.amazonaws.com" + ], + eventName: [ + "GetObject" + ], + requestParameters: { + bucketName: [ + { + Ref: "mybucket160F8132" + } + ] + } + } + }, + State: "ENABLED", + Targets: [ + { + Arn: { + Ref: "tests3stepfunctiontesteventsrulestepfunctionstackStateMachine5A6C0DFF" + }, + Id: "Target0", + RoleArn: { + "Fn::GetAtt": [ + "tests3stepfunctiontesteventsrulestepfunctionstackEventsRuleRoleF447A174", + "Arn" + ] + } + } + ] + }); +}); + +test('check properties', () => { + const stack = new cdk.Stack(); + + const construct: S3ToStepFunction = deployNewStateMachine(stack); + + expect(construct.cloudtrail !== null); + expect(construct.stateMachine !== null); + expect(construct.s3Bucket !== null); + expect(construct.cloudwatchAlarms !== null); +}); diff --git a/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.eslintignore new file mode 100644 index 000000000..0819e2e65 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.eslintignore @@ -0,0 +1,5 @@ +lib/*.js +test/*.js +*.d.ts +coverage +test/lambda/index.js \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.gitignore new file mode 100644 index 000000000..8626f2274 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.gitignore @@ -0,0 +1,16 @@ +lib/*.js +test/*.js +!test/lambda/* +*.js.map +*.d.ts +node_modules +*.generated.ts +dist +.jsii + +.LAST_BUILD +.nyc_output +coverage +.nycrc +.LAST_PACKAGE +*.snk \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/.npmignore b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/.npmignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/.npmignore rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/.npmignore diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md similarity index 70% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md index 5fc948a44..4ebb008e2 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-sns-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_sns_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-sns-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_sns_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-sns-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.snslambda`| -This AWS Solutions Konstruk implements an Amazon SNS connected to an AWS Lambda function. +This AWS Solutions Construct implements an Amazon SNS connected to an AWS Lambda function. Here is a minimal deployable pattern definition: ``` javascript -const { SnsToLambdaProps, SnsToLambda } = require('@aws-solutions-konstruk/aws-sns-lambda'); +const { SnsToLambdaProps, SnsToLambda } = require('@aws-solutions-constructs/aws-sns-lambda'); const stack = new Stack(app, 'test-sns-lambda'); @@ -73,8 +72,20 @@ _Parameters_ | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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.| -|snsTopic()|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of the SNS topic created by the pattern.| +|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.| +|snsTopic|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of the SNS topic created by the pattern.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon SNS Topic +* Configure least privilege access permissions for SNS Topic +* Enable server-side encryption forSNS Topic using Customer managed KMS Key + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/lib/index.ts similarity index 78% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/lib/index.ts index 8d78984e5..1a7adc352 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/lib/index.ts @@ -14,7 +14,7 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as sns from '@aws-cdk/aws-sns'; import * as kms from '@aws-cdk/aws-kms'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; import { SnsEventSource } from '@aws-cdk/aws-lambda-event-sources'; @@ -68,9 +68,8 @@ export interface SnsToLambdaProps { * @summary The SnsToLambda class. */ export class SnsToLambda extends Construct { - // Private variables - private fn: lambda.Function; - private topic: sns.Topic; + public readonly lambdaFunction: lambda.Function; + public readonly snsTopic: sns.Topic; /** * @summary Constructs a new instance of the LambdaToSns class. @@ -84,39 +83,18 @@ export class SnsToLambda extends Construct { super(scope, id); // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps }); // Setup the SNS topic - this.topic = defaults.buildTopic(this, { + this.snsTopic = defaults.buildTopic(this, { enableEncryption: props.enableEncryption, encryptionKey: props.encryptionKey }); - this.fn.addEventSource(new SnsEventSource(this.topic)); - - } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of the sns.Topic created by the construct. - * @returns {sns.Topic} Instance of the Topic created by the construct. - * @since 0.8.0 - * @access public - */ - public snsTopic(): sns.Topic { - return this.topic; + this.lambdaFunction.addEventSource(new SnsEventSource(this.snsTopic)); } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/package.json similarity index 56% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/package.json index 2d319da18..91f377ca5 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-sns-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-sns-lambda", + "version": "1.46.0", "description": "CDK Constructs for AWS SNS to AWS Lambda integration", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-sns-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-sns-lambda" }, "author": { "name": "Amazon Web Services", @@ -34,36 +34,36 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.snslambda", + "package": "software.amazon.awsconstructs.services.snslambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "snslambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.SnsLambda", - "packageId": "Amazon.Konstruk.AWS.SnsLambda", + "namespace": "Amazon.Constructs.AWS.SnsLambda", + "packageId": "Amazon.Constructs.AWS.SnsLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-sns-lambda", - "module": "aws_solutions_konstruk.aws_sns_lambda" + "distName": "aws-solutions-constructs.aws-sns-lambda", + "module": "aws_solutions_constructs.aws_sns_lambda" } } }, "dependencies": { - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -73,13 +73,13 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-kms": "~1.40.0", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/__snapshots__/sns-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/__snapshots__/sns-lambda.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/__snapshots__/sns-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/__snapshots__/sns-lambda.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/integ.no-arguments.expected.json b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/integ.no-arguments.expected.json similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/integ.no-arguments.expected.json rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/integ.no-arguments.expected.json diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/integ.no-arguments.ts b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/integ.no-arguments.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/integ.no-arguments.ts rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/integ.no-arguments.ts diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/sns-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/sns-lambda.test.ts similarity index 87% rename from source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/sns-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/sns-lambda.test.ts index 3db6f010e..bd3265fae 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sns-lambda/test/sns-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/test/sns-lambda.test.ts @@ -16,7 +16,6 @@ import { SnsToLambda, SnsToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from "@aws-cdk/core"; import '@aws-cdk/assert/jest'; -import { Topic } from '@aws-cdk/aws-sns'; function deployNewFunc(stack: cdk.Stack) { const props: SnsToLambdaProps = { @@ -37,11 +36,11 @@ test('snapshot test SnsToLambda default params', () => { expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); }); -test('check getter methods', () => { +test('check properties', () => { const stack = new cdk.Stack(); const construct: SnsToLambda = deployNewFunc(stack); - expect(construct.lambdaFunction()).toBeInstanceOf(lambda.Function); - expect(construct.snsTopic()).toBeInstanceOf(Topic); + expect(construct.lambdaFunction !== null); + expect(construct.snsTopic !== null); }); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.eslintignore b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.eslintignore new file mode 100644 index 000000000..0819e2e65 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.eslintignore @@ -0,0 +1,5 @@ +lib/*.js +test/*.js +*.d.ts +coverage +test/lambda/index.js \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.gitignore b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/.gitignore rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.gitignore diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.npmignore b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.npmignore new file mode 100644 index 000000000..f66791629 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/.npmignore @@ -0,0 +1,21 @@ +# Exclude typescript source and config +*.ts +tsconfig.json +coverage +.nyc_output +*.tgz +*.snk +*.tsbuildinfo + +# Include javascript files and typescript declarations +!*.js +!*.d.ts + +# Exclude jsii outdir +dist + +# Include .jsii +!.jsii + +# Include .jsii +!.jsii \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md similarity index 64% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/README.md rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md index 91330d7b9..505ba9453 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md @@ -5,8 +5,6 @@ ![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) -> **This is a _developer preview_ (public beta) module.** -> > All classes are under active development and subject to non-backward compatible changes or removal in any > future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. > This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. @@ -14,21 +12,22 @@ --- -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/aws-sqs-lambda/| +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| |:-------------|:-------------|
| **Language** | **Package** | |:-------------|-----------------| -|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png){: style="height:16px;width:16px"} Python|`aws_solutions_konstruk.aws_sns_lambda`| -|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png){: style="height:16px;width:16px"} Typescript|`@aws-solutions-konstruk/aws-sns-lambda`| +|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_sns_lambda`| +|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-sns-lambda`| +|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.sqslambda`| -This AWS Solutions Konstruk implements an Amazon SQS queue connected to an AWS Lambda function. +This AWS Solutions Construct implements an Amazon SQS queue connected to an AWS Lambda function. Here is a minimal deployable pattern definition: ``` javascript -const { SqsToLambda } = require('@aws-solutions-konstruk/aws-sqs-lambda'); +const { SqsToLambda } = require('@aws-solutions-constructs/aws-sqs-lambda'); new SqsToLambda(stack, 'SqsToLambdaPattern', { deployLambda: true, @@ -61,16 +60,27 @@ _Parameters_ |existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|An optional, existing Lambda function.| |lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|Optional user-provided props to override the default props for the Lambda function.| |queueProps?|[`sqs.QueueProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.QueueProps.html)|Optional user-provided props to override the default props for the SQS queue.| -|encryptionKeyProps?|[`kms.KeyProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kms.KeyProps.html)|Optional user-provided props to override the default props for the KMS encryption key.| |deployDeadLetterQueue?|`boolean`|Whether to create a secondary queue to be used as a dead letter queue. Defaults to true.| -|maxReceiveCount?|`number`|The number of times a message can be unsuccesfully dequeued before being moved to the dead letter queue. Defaults to 15.| +|maxReceiveCount?|`number`|The number of times a message can be unsuccessfully dequeued before being moved to the dead letter queue. Defaults to 15.| ## Pattern Properties | **Name** | **Type** | **Description** | |:-------------|:----------------|-----------------| -|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.| -|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.| +|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.| +|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.| + +## Default settings + +Out of the box implementation of the Construct without any override will set the following defaults: + +### Amazon SQS Queue +* Deploy SQS dead-letter queue for the source SQS Queue +* Enable server-side encryption for source SQS Queue using AWS Managed KMS Key + +### AWS Lambda Function +* Configure least privilege access IAM role for Lambda function +* Enable reusing connections with Keep-Alive for NodeJs Lambda function ## Architecture ![Architecture Diagram](architecture.png) diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/architecture.png b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/architecture.png similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/architecture.png rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/architecture.png diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/lib/index.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/lib/index.ts similarity index 70% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/lib/index.ts rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/lib/index.ts index 96342ac68..e5feec38a 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/lib/index.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/lib/index.ts @@ -14,8 +14,7 @@ // Imports import * as sqs from '@aws-cdk/aws-sqs'; import * as lambda from '@aws-cdk/aws-lambda'; -import * as kms from '@aws-cdk/aws-kms'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources'; @@ -50,12 +49,6 @@ export interface SqsToLambdaProps { * @default - Default props are used */ readonly queueProps?: sqs.QueueProps | any - /** - * Optional user provided props to override the default props for the KMS. - * - * @default - Default props are used - */ - readonly encryptionKeyProps?: kms.KeyProps | any /** * Whether to deploy a secondary queue to be used as a dead letter queue. * @@ -63,7 +56,7 @@ export interface SqsToLambdaProps { */ readonly deployDeadLetterQueue?: boolean, /** - * The number of times a message can be unsuccesfully dequeued before being moved to the dead-letter queue. + * The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue. * * @default - required field if deployDeadLetterQueue=true. */ @@ -74,10 +67,8 @@ export interface SqsToLambdaProps { * @summary The SqsToLambda class. */ export class SqsToLambda extends Construct { - // Private variables - private queue: sqs.Queue; - private fn: lambda.Function; - private encryptionKey: kms.Key; + public readonly sqsQueue: sqs.Queue; + public readonly lambdaFunction: lambda.Function; /** * @summary Constructs a new instance of the SqsToLambda class. @@ -90,11 +81,8 @@ export class SqsToLambda extends Construct { constructor(scope: Construct, id: string, props: SqsToLambdaProps) { super(scope, id); - // Setup the encryption key - this.encryptionKey = defaults.buildEncryptionKey(this, props.encryptionKeyProps); - // Setup the Lambda function - this.fn = defaults.buildLambdaFunction(this, { + this.lambdaFunction = defaults.buildLambdaFunction(this, { deployLambda: props.deployLambda, existingLambdaObj: props.existingLambdaObj, lambdaFunctionProps: props.lambdaFunctionProps @@ -104,7 +92,6 @@ export class SqsToLambda extends Construct { let dlqi: sqs.DeadLetterQueue | undefined; if (props.deployDeadLetterQueue || props.deployDeadLetterQueue === undefined) { const dlq: sqs.Queue = defaults.buildQueue(this, 'deadLetterQueue', { - encryptionKey: this.encryptionKey, queueProps: props.queueProps }); dlqi = defaults.buildDeadLetterQueue({ @@ -114,33 +101,12 @@ export class SqsToLambda extends Construct { } // Setup the queue - this.queue = defaults.buildQueue(this, 'queue', { - encryptionKey: this.encryptionKey, + this.sqsQueue = defaults.buildQueue(this, 'queue', { queueProps: props.queueProps, deadLetterQueue: dlqi }); // Setup the event source mapping - this.fn.addEventSource(new SqsEventSource(this.queue)); - } - - /** - * @summary Returns an instance of the lambda.Function created by the construct. - * @returns {lambda.Function} Instance of the Function created by the construct. - * @since 0.8.0 - * @access public - */ - public lambdaFunction(): lambda.Function { - return this.fn; - } - - /** - * @summary Returns an instance of the sqs.Queue created by the construct. - * @returns {sqs.Queue} Instance of the Queue created by the construct. - * @since 0.8.0 - * @access public - */ - public sqsQueue(): sqs.Queue { - return this.queue; + this.lambdaFunction.addEventSource(new SqsEventSource(this.sqsQueue)); } } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/package.json b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/package.json similarity index 57% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/package.json rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/package.json index c424739a3..db8398901 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/package.json +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-solutions-konstruk/aws-sqs-lambda", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-sqs-lambda", + "version": "1.46.0", "description": "CDK constructs for defining an interaction between an Amazon SQS queue and an AWS Lambda function.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-sqs-lambda" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-sqs-lambda" }, "author": { "name": "Amazon Web Services", @@ -24,6 +24,7 @@ "watch": "tsc -b -w", "integ": "cdk-integ", "integ-assert": "cdk-integ-assert", + "integ-no-clean": "cdk-integ --no-clean", "jsii": "jsii", "jsii-pacmak": "jsii-pacmak", "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", @@ -33,35 +34,35 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.sqslambda", + "package": "software.amazon.awsconstructs.services.sqslambda", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "sqslambda" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.SqsLambda", - "packageId": "Amazon.Konstruk.AWS.SqsLambda", + "namespace": "Amazon.Constructs.AWS.SqsLambda", + "packageId": "Amazon.Constructs.AWS.SqsLambda", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-solutions-konstruk.aws-sqs-lambda", - "module": "aws_solutions_konstruk.aws_sqs_lambda" + "distName": "aws-solutions-constructs.aws-sqs-lambda", + "module": "aws_solutions_constructs.aws_sqs_lambda" } } }, "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -71,12 +72,12 @@ ] }, "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "constructs": "^3.0.2" } } diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap similarity index 70% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap index 9d6935a2d..47e41e820 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/__snapshots__/test.sqs-lambda.test.js.snap @@ -123,16 +123,6 @@ Object { ], }, }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "testapigatewaylambdaEncryptionKey06FC467F", - "Arn", - ], - }, - }, ], "Version": "2012-10-17", }, @@ -159,79 +149,9 @@ Object { }, "Type": "AWS::Lambda::EventSourceMapping", }, - "testapigatewaylambdaEncryptionKey06FC467F": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "ExistingLambdaFunctionServiceRole7CC6DE65", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "testapigatewaylambdaqueue1FFAE03C": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "testapigatewaylambdaEncryptionKey06FC467F", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", }, "Type": "AWS::SQS::Queue", }, @@ -256,71 +176,6 @@ Object { }, }, "Resources": Object { - "testsqslambdaEncryptionKey317A2F03": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::GetAtt": Array [ - "testsqslambdaLambdaFunctionServiceRoleF623B438", - "Arn", - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, "testsqslambdaLambdaFunction58720146": Object { "DependsOn": Array [ "testsqslambdaLambdaFunctionServiceRoleDefaultPolicy380B065C", @@ -411,16 +266,6 @@ Object { ], }, }, - Object { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": Object { - "Fn::GetAtt": Array [ - "testsqslambdaEncryptionKey317A2F03", - "Arn", - ], - }, - }, ], "Version": "2012-10-17", }, @@ -500,23 +345,13 @@ Object { }, "testsqslambdadeadLetterQueue85BDB0A3": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "testsqslambdaEncryptionKey317A2F03", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", }, "Type": "AWS::SQS::Queue", }, "testsqslambdaqueue601203B8": Object { "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "testsqslambdaEncryptionKey317A2F03", - "Arn", - ], - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": Object { "deadLetterTargetArn": Object { "Fn::GetAtt": Array [ diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.expected.json similarity index 72% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.expected.json index 790d01994..f4ef34d88 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.expected.json @@ -1,71 +1,6 @@ { "Description": "Integration Test for aws-sqs-lambda", "Resources": { - "testsqslambdaEncryptionKey317A2F03": { - "Type": "AWS::KMS::Key", - "Properties": { - "KeyPolicy": { - "Statement": [ - { - "Action": [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "testsqslambdaLambdaFunctionServiceRoleF623B438", - "Arn" - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "EnableKeyRotation": true - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "testsqslambdaLambdaFunctionServiceRoleF623B438": { "Type": "AWS::IAM::Role", "Properties": { @@ -137,16 +72,6 @@ "Arn" ] } - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - } } ], "Version": "2012-10-17" @@ -246,23 +171,13 @@ "testsqslambdadeadLetterQueue85BDB0A3": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - } + "KmsMasterKeyId": "alias/aws/sqs" } }, "testsqslambdaqueue601203B8": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": { "deadLetterTargetArn": { "Fn::GetAtt": [ diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.ts similarity index 96% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.ts index 6858f97c5..cacd982b4 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.deployFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.deployFunction.ts @@ -31,8 +31,7 @@ const props: SqsToLambdaProps = { }, queueProps: {}, deployDeadLetterQueue: true, - maxReceiveCount: 3, - encryptionKeyProps: {} + maxReceiveCount: 3 }; new SqsToLambda(stack, 'test-sqs-lambda', props); diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.expected.json b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.expected.json similarity index 72% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.expected.json rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.expected.json index 63114433d..0cfc28750 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.expected.json +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.expected.json @@ -72,16 +72,6 @@ "Arn" ] } - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - } } ], "Version": "2012-10-17" @@ -178,91 +168,16 @@ } } }, - "testsqslambdaEncryptionKey317A2F03": { - "Type": "AWS::KMS::Key", - "Properties": { - "KeyPolicy": { - "Statement": [ - { - "Action": [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource" - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "LambdaFunctionServiceRole0C4CDE0B", - "Arn" - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "EnableKeyRotation": true - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "testsqslambdadeadLetterQueue85BDB0A3": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - } + "KmsMasterKeyId": "alias/aws/sqs" } }, "testsqslambdaqueue601203B8": { "Type": "AWS::SQS::Queue", "Properties": { - "KmsMasterKeyId": { - "Fn::GetAtt": [ - "testsqslambdaEncryptionKey317A2F03", - "Arn" - ] - }, + "KmsMasterKeyId": "alias/aws/sqs", "RedrivePolicy": { "deadLetterTargetArn": { "Fn::GetAtt": [ diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.ts similarity index 92% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.ts rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.ts index 63337bc51..6bc7b9fbf 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/integ.existingFunction.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/integ.existingFunction.ts @@ -15,7 +15,7 @@ import { App, Stack } from "@aws-cdk/core"; import { SqsToLambda, SqsToLambdaProps } from "../lib"; import * as lambda from '@aws-cdk/aws-lambda'; -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; // Setup const app = new App(); @@ -36,8 +36,7 @@ const props: SqsToLambdaProps = { existingLambdaObj: func, queueProps: {}, deployDeadLetterQueue: true, - maxReceiveCount: 3, - encryptionKeyProps: {} + maxReceiveCount: 3 }; new SqsToLambda(stack, 'test-sqs-lambda', props); diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/lambda/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/lambda/index.js rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/lambda/index.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/test.sqs-lambda.test.ts b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/test.sqs-lambda.test.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/test.sqs-lambda.test.ts rename to source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/test.sqs-lambda.test.ts index 171bc25b5..ddcb5fe64 100644 --- a/source/patterns/@aws-solutions-konstruk/aws-sqs-lambda/test/test.sqs-lambda.test.ts +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/test/test.sqs-lambda.test.ts @@ -58,15 +58,14 @@ test('Pattern deployment w/ new Lambda function and overridden props', () => { queueProps: { fifo: true }, - encryptionKeyProps: {}, deployDeadLetterQueue: false, maxReceiveCount: 0 }; const app = new SqsToLambda(stack, 'test-sqs-lambda', props); // Assertion 1 - expect(app.lambdaFunction()).toHaveProperty('environment.OVERRIDE', 'TRUE'); + expect(app.lambdaFunction).toHaveProperty('environment.OVERRIDE', 'TRUE'); // Assertion 2 - expect(app.sqsQueue()).toHaveProperty('fifo', true); + expect(app.sqsQueue).toHaveProperty('fifo', true); }); // -------------------------------------------------------------- @@ -84,7 +83,6 @@ test('Pattern deployment w/ Existing Lambda Function', () => { deployLambda: false, existingLambdaObj: fn, deployDeadLetterQueue: false, - encryptionKeyProps: {}, maxReceiveCount: 0, queueProps: {} }; @@ -107,15 +105,14 @@ test('Test getter methods', () => { code: lambda.Code.asset(`${__dirname}/lambda`) }, deployDeadLetterQueue: false, - encryptionKeyProps: {}, maxReceiveCount: 0, queueProps: {} }; const app = new SqsToLambda(stack, 'test-apigateway-lambda', props); // Assertion 1 - expect(app.lambdaFunction()).toBeDefined(); + expect(app.lambdaFunction !== null); // Assertion 2 - expect(app.sqsQueue()).toBeDefined(); + expect(app.sqsQueue !== null); }); // -------------------------------------------------------------- @@ -128,7 +125,6 @@ test('Test error handling for existing Lambda function', () => { deployLambda: false, existingLambdaObj: undefined, deployDeadLetterQueue: false, - encryptionKeyProps: {}, maxReceiveCount: 0, queueProps: {} }; @@ -148,7 +144,6 @@ test('Test error handling for new Lambda function w/o required properties', () = const props: SqsToLambdaProps = { deployLambda: true, deployDeadLetterQueue: false, - encryptionKeyProps: {}, maxReceiveCount: 0, queueProps: {} }; diff --git a/source/patterns/@aws-solutions-konstruk/core/.eslintignore b/source/patterns/@aws-solutions-constructs/core/.eslintignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/.eslintignore rename to source/patterns/@aws-solutions-constructs/core/.eslintignore diff --git a/source/patterns/@aws-solutions-konstruk/core/.gitignore b/source/patterns/@aws-solutions-constructs/core/.gitignore similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/.gitignore rename to source/patterns/@aws-solutions-constructs/core/.gitignore diff --git a/source/patterns/@aws-solutions-constructs/core/.npmignore b/source/patterns/@aws-solutions-constructs/core/.npmignore new file mode 100644 index 000000000..f66791629 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/.npmignore @@ -0,0 +1,21 @@ +# Exclude typescript source and config +*.ts +tsconfig.json +coverage +.nyc_output +*.tgz +*.snk +*.tsbuildinfo + +# Include javascript files and typescript declarations +!*.js +!*.d.ts + +# Exclude jsii outdir +dist + +# Include .jsii +!.jsii + +# Include .jsii +!.jsii \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/README.md b/source/patterns/@aws-solutions-constructs/core/README.md new file mode 100644 index 000000000..6ad6952bb --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/README.md @@ -0,0 +1,81 @@ +# core module + + +--- + +![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) + +> All classes are under active development and subject to non-backward compatible changes or removal in any +> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. +> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. + +--- + + +| **Reference Documentation**:| https://docs.aws.amazon.com/solutions/latest/constructs/| +|:-------------|:-------------| +
+ +The core library includes the basic building blocks of the AWS Solutions Constructs Library. It defines the core classes that are used in the rest of the AWS Solutions Constructs Library. + +## Default Properties for AWS CDK Constructs + +Core library sets the default properties for the AWS CDK Constructs used by the AWS Solutions Constructs Library constructs. + +For example, the following is the snippet of default properties for S3 Bucket construct created by AWS Solutions Constructs. By default, it will turn on the server-side encryption, bucket versioning, block all public access and setup the S3 access logging. + +``` +{ + encryption: s3.BucketEncryption.S3_MANAGED, + versioned: true, + blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, + removalPolicy: RemovalPolicy.RETAIN, + serverAccessLogsBucket: loggingBucket +} +``` + +## Override the default properties + +The default properties set by the Core library can be overridden by user provided properties. For example, the user can override the Amazon S3 Block Public Access property to meet specific requirements. + +``` + const stack = new cdk.Stack(); + + const props: CloudFrontToS3Props = { + deployBucket: true, + bucketProps: { + blockPublicAccess: { + blockPublicAcls: false, + blockPublicPolicy: true, + ignorePublicAcls: false, + restrictPublicBuckets: true + } + } + }; + + new CloudFrontToS3(stack, 'test-cloudfront-s3', props); + + expect(stack).toHaveResource("AWS::S3::Bucket", { + PublicAccessBlockConfiguration: { + BlockPublicAcls: false, + BlockPublicPolicy: true, + IgnorePublicAcls: false, + RestrictPublicBuckets: true + }, + }); +``` + +## Property override warnings + +When a default property from the Core library is overridden by a user-provided property, Constructs will emit one or more warning messages to the console highlighting the change(s). These messages are intended to provide situational awareness to the user and prevent unintentional overrides that could create security risks. These messages will appear whenever deployment/build-related commands are executed, including `cdk deploy`, `cdk synth`, `npm test`, etc. + +Example message: +`AWS_CONSTRUCTS_WARNING: An override has been provided for the property: BillingMode. Default value: 'PAY_PER_REQUEST'. You provided: 'PROVISIONED'.` + +#### Toggling override warnings + +Override warning messages are enabled by default, but can be explicitly turned on/off using the `overrideWarningsEnabled` shell variable. + +- To explicitly turn off override warnings, run `export overrideWarningsEnabled=false`. +- To explicitly turn on override warnings, run `export overrideWarningsEnabled=true`. +- To revert to the default, run `unset overrideWarningsEnabled`. \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/index.ts b/source/patterns/@aws-solutions-constructs/core/index.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/core/index.ts rename to source/patterns/@aws-solutions-constructs/core/index.ts index a8de6950e..743cf0a8b 100644 --- a/source/patterns/@aws-solutions-konstruk/core/index.ts +++ b/source/patterns/@aws-solutions-constructs/core/index.ts @@ -39,4 +39,6 @@ export * from './lib/events-rule-defaults'; export * from './lib/cognito-defaults'; export * from './lib/cognito-helper'; export * from './lib/elasticsearch-defaults'; -export * from './lib/elasticsearch-helper'; \ No newline at end of file +export * from './lib/elasticsearch-helper'; +export * from './lib/step-function-defaults'; +export * from './lib/step-function-helper'; \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/apigateway-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/apigateway-defaults.ts similarity index 97% rename from source/patterns/@aws-solutions-konstruk/core/lib/apigateway-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/apigateway-defaults.ts index c2a490e4b..3ae91021d 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/apigateway-defaults.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/apigateway-defaults.ts @@ -23,7 +23,9 @@ import { LogGroup } from '@aws-cdk/aws-logs'; */ function DefaultRestApiProps(_endpointType: api.EndpointType[], _logGroup: LogGroup): api.RestApiProps { return { - endpointTypes: _endpointType, + endpointConfiguration: { + types: _endpointType + }, cloudWatchRole: false, // Configure API Gateway Access logging deployOptions: { diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/apigateway-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/apigateway-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/apigateway-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/cloudfront-distribution-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/cloudfront-distribution-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/cloudfront-distribution-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/cloudfront-distribution-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/cloudfront-distribution-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/cloudfront-distribution-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/cloudfront-distribution-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/cloudfront-distribution-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/cloudwatch-log-group-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/cloudwatch-log-group-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/cloudwatch-log-group-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/cloudwatch-log-group-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/cognito-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/cognito-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/cognito-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/cognito-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/cognito-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/cognito-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/cognito-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/cognito-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/dynamodb-table-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-defaults.ts similarity index 91% rename from source/patterns/@aws-solutions-konstruk/core/lib/dynamodb-table-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-defaults.ts index a3921a915..cb899b1a7 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/dynamodb-table-defaults.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-defaults.ts @@ -15,7 +15,7 @@ import * as dynamodb from '@aws-cdk/aws-dynamodb'; const DefaultTableProps: dynamodb.TableProps = { billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, - serverSideEncryption: true, + encryption: dynamodb.TableEncryption.AWS_MANAGED, partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING @@ -24,7 +24,7 @@ const DefaultTableProps: dynamodb.TableProps = { const DefaultTableWithStreamProps: dynamodb.TableProps = { billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, - serverSideEncryption: true, + encryption: dynamodb.TableEncryption.AWS_MANAGED, partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/elasticsearch-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/elasticsearch-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/elasticsearch-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/elasticsearch-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/elasticsearch-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/elasticsearch-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/elasticsearch-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/elasticsearch-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/events-rule-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/events-rule-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/events-rule-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/events-rule-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/iot-topic-rule-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/iot-topic-rule-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/iot-topic-rule-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/iot-topic-rule-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-analytics-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-analytics-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/kinesis-analytics-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kinesis-analytics-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-analytics-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-analytics-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/kinesis-analytics-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kinesis-analytics-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-firehose-s3-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-firehose-s3-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/kinesis-firehose-s3-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kinesis-firehose-s3-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-defaults.ts similarity index 93% rename from source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-defaults.ts index ef20c82d8..11fe21d18 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-defaults.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-defaults.ts @@ -14,7 +14,7 @@ import * as kinesis from '@aws-cdk/aws-kinesis'; const DefaultStreamProps: kinesis.StreamProps = { - encryption: kinesis.StreamEncryption.KMS + encryption: kinesis.StreamEncryption.MANAGED }; export { DefaultStreamProps }; \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-helper.ts similarity index 80% rename from source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-helper.ts index dd69f3446..456207e73 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/kinesis-streams-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/kinesis-streams-helper.ts @@ -13,18 +13,11 @@ // Imports import * as kinesis from '@aws-cdk/aws-kinesis'; -import * as kms from '@aws-cdk/aws-kms'; import { DefaultStreamProps } from './kinesis-streams-defaults'; import * as cdk from '@aws-cdk/core'; import { overrideProps } from './utils'; export interface BuildKinesisStreamProps { - /** - * Optional external encryption key to use for stream encryption. - * - * @default - Default props are used. - */ - readonly encryptionKey?: kms.Key /** * Optional user provided props to override the default props for the Kinesis stream. * @@ -45,10 +38,7 @@ export function buildKinesisStream(scope: cdk.Construct, props?: BuildKinesisStr // If no property overrides, deploy using the default configuration kinesisStreamProps = DefaultStreamProps; } - // Set conditional stream encryption properties - if (!kinesisStreamProps.hasOwnProperty('encryptionKey') && props.hasOwnProperty('kinesisStreamProps')) { - kinesisStreamProps.encryptionKey = props.encryptionKey; - } + // Create the stream and return return new kinesis.Stream(scope, 'KinesisStream', kinesisStreamProps); } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kms-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/kms-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/kms-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kms-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/kms-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/kms-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/kms-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/kms-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/lambda-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/lambda-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/lambda-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/lambda-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/lambda-event-source-mapping-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/lambda-event-source-mapping-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/lambda-event-source-mapping-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/lambda-event-source-mapping-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/lambda-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/lambda-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/lambda-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/lambda-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/override-warning-service.ts b/source/patterns/@aws-solutions-constructs/core/lib/override-warning-service.ts similarity index 94% rename from source/patterns/@aws-solutions-konstruk/core/lib/override-warning-service.ts rename to source/patterns/@aws-solutions-constructs/core/lib/override-warning-service.ts index 973e89ecf..cb49b9238 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/override-warning-service.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/override-warning-service.ts @@ -16,7 +16,7 @@ import * as log from 'npmlog'; /** * Emits a warning to the console when a prescriptive default value is overridden by the user. - * @param {objet} defaultProps the prescriptive defaults for the pattern. + * @param {object} defaultProps the prescriptive defaults for the pattern. * @param {object} userProps the properties provided by the user, to be compared against the defaultProps. */ export function flagOverriddenDefaults(defaultProps: object, userProps: object) { @@ -38,7 +38,7 @@ export function flagOverriddenDefaults(defaultProps: object, userProps: object) log.enableColor(); // Output const details = (valuesAreReadable) ? ` Default value: '${e.lhs}'. You provided: '${e.rhs}'.` : ''; - log.warn('AWS_KONSTRUK_WARNING: ', `An override has been provided for the property: ${path}.` + details); + log.warn('AWS_SOLUTIONS_CONSTRUCTS_WARNING: ', `An override has been provided for the property: ${path}.` + details); } } diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/s3-bucket-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/s3-bucket-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/s3-bucket-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/s3-bucket-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/s3-bucket-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/s3-bucket-helper.ts similarity index 84% rename from source/patterns/@aws-solutions-konstruk/core/lib/s3-bucket-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/s3-bucket-helper.ts index 4a01a1df7..6f18950af 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/s3-bucket-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/s3-bucket-helper.ts @@ -40,7 +40,7 @@ export interface BuildS3BucketProps { readonly bucketProps?: s3.BucketProps } -export function buildS3Bucket(scope: cdk.Construct, props: BuildS3BucketProps): s3.Bucket { +export function buildS3Bucket(scope: cdk.Construct, props: BuildS3BucketProps, bucketId?: string): s3.Bucket { // Conditional s3 Bucket creation // If deployBucket == false if (props.hasOwnProperty('deployBucket') && props.deployBucket === false) { @@ -52,23 +52,25 @@ export function buildS3Bucket(scope: cdk.Construct, props: BuildS3BucketProps): // If deploy == true } else { if (props.bucketProps) { - return s3BucketWithLogging(scope, props.bucketProps); + return s3BucketWithLogging(scope, props.bucketProps, bucketId); } else { - return s3BucketWithLogging(scope, DefaultS3Props()); + return s3BucketWithLogging(scope, DefaultS3Props(), bucketId); } } } -function s3BucketWithLogging(scope: cdk.Construct, s3BucketProps?: s3.BucketProps): s3.Bucket { +function s3BucketWithLogging(scope: cdk.Construct, s3BucketProps?: s3.BucketProps, bucketId?: string): s3.Bucket { // Create the Application Bucket let bucketprops; + const _bucketId = bucketId ? bucketId + 'S3Bucket' : 'S3Bucket'; + const _loggingBucketId = bucketId ? bucketId + 'S3LoggingBucket' : 'S3LoggingBucket'; if (s3BucketProps?.serverAccessLogsBucket) { bucketprops = DefaultS3Props; } else { // Create the Logging Bucket - const loggingBucket: s3.Bucket = new s3.Bucket(scope, 'S3LoggingBucket', DefaultS3Props()); + const loggingBucket: s3.Bucket = new s3.Bucket(scope, _loggingBucketId, DefaultS3Props()); // Extract the CfnBucket from the loggingBucket const loggingBucketResource = loggingBucket.node.findChild('Resource') as s3.CfnBucket; @@ -92,7 +94,7 @@ function s3BucketWithLogging(scope: cdk.Construct, s3BucketProps?: s3.BucketProp if (s3BucketProps) { bucketprops = overrideProps(bucketprops, s3BucketProps); } - const s3Bucket: s3.Bucket = new s3.Bucket(scope, 'S3Bucket', bucketprops); + const s3Bucket: s3.Bucket = new s3.Bucket(scope, _bucketId, bucketprops); return s3Bucket; } \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/sns-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/sns-defaults.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/sns-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/sns-defaults.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/sns-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/sns-helper.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/sns-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/sns-helper.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/sqs-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/sqs-defaults.ts similarity index 80% rename from source/patterns/@aws-solutions-konstruk/core/lib/sqs-defaults.ts rename to source/patterns/@aws-solutions-constructs/core/lib/sqs-defaults.ts index d092731d8..590c66470 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/sqs-defaults.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/sqs-defaults.ts @@ -12,12 +12,10 @@ */ import * as sqs from '@aws-cdk/aws-sqs'; -import * as kms from '@aws-cdk/aws-kms'; -export function DefaultQueueProps(_encryptionMasterKey?: kms.Key) { +export function DefaultQueueProps() { const _DefaultQueueProps: sqs.QueueProps = { - encryption: sqs.QueueEncryption.KMS, - encryptionMasterKey: _encryptionMasterKey + encryption: sqs.QueueEncryption.KMS_MANAGED }; return _DefaultQueueProps; } diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/sqs-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/sqs-helper.ts similarity index 83% rename from source/patterns/@aws-solutions-konstruk/core/lib/sqs-helper.ts rename to source/patterns/@aws-solutions-constructs/core/lib/sqs-helper.ts index a2193e40e..bdf5da2bb 100644 --- a/source/patterns/@aws-solutions-konstruk/core/lib/sqs-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/sqs-helper.ts @@ -13,18 +13,11 @@ // Imports import * as sqs from '@aws-cdk/aws-sqs'; -import * as kms from '@aws-cdk/aws-kms'; import * as defaults from './sqs-defaults'; import * as cdk from '@aws-cdk/core'; import { overrideProps } from './utils'; export interface BuildQueueProps { - /** - * Optional external encryption key to use for stream encryption. - * - * @default - Default props are used. - */ - readonly encryptionKey?: kms.Key /** * Optional user provided props to override the default props for the primary queue. * @@ -46,10 +39,10 @@ export function buildQueue(scope: cdk.Construct, id: string, props?: BuildQueueP let queueProps; if (props.queueProps) { // If property overrides have been provided, incorporate them and deploy - queueProps = overrideProps(defaults.DefaultQueueProps(props.encryptionKey), props.queueProps); + queueProps = overrideProps(defaults.DefaultQueueProps(), props.queueProps); } else { // If no property overrides, deploy using the default configuration - queueProps = defaults.DefaultQueueProps(props.encryptionKey); + queueProps = defaults.DefaultQueueProps(); } // Determine whether a DLQ property should be added if (props.deadLetterQueue) { @@ -67,7 +60,7 @@ export interface BuildDeadLetterQueueProps { */ readonly deadLetterQueue: sqs.Queue /** - * The number of times a message can be unsuccesfully dequeued before being moved to the dead-letter queue. + * The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue. * * @default - Default props are used */ diff --git a/source/patterns/@aws-solutions-constructs/core/lib/step-function-defaults.ts b/source/patterns/@aws-solutions-constructs/core/lib/step-function-defaults.ts new file mode 100644 index 000000000..21160ba9b --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/lib/step-function-defaults.ts @@ -0,0 +1,27 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import { LogGroup } from '@aws-cdk/aws-logs'; + +export function DefaultStateMachineProps(_logGroup: LogGroup): sfn.StateMachineProps | any { + + const stateMachineProps: sfn.StateMachineProps | any = { + logs: { + destination: _logGroup, + level: sfn.LogLevel.ERROR + } + }; + + return stateMachineProps; +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts new file mode 100644 index 000000000..2b3ca5345 --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/lib/step-function-helper.ts @@ -0,0 +1,119 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +// Imports +import { LogGroup } from '@aws-cdk/aws-logs'; +import * as cdk from '@aws-cdk/core'; +import * as smDefaults from './step-function-defaults'; +import { DefaultLogGroupProps } from './cloudwatch-log-group-defaults'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import { overrideProps } from './utils'; +import * as iam from '@aws-cdk/aws-iam'; +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; + +/** + * Builds and returns a StateMachine. + * @param scope - the construct to which the StateMachine should be attached to. + * @param stateMachineProps - user-specified properties to override the default properties. + */ +export function buildStateMachine(scope: cdk.Construct, stateMachineProps: sfn.StateMachineProps): sfn.StateMachine { + + let logGroup: LogGroup; + + // Configure Cloudwatch log group for Step function State Machine + if (!stateMachineProps.logs) { + logGroup = new LogGroup(scope, 'StateMachineLogGroup', DefaultLogGroupProps()); + } else { + logGroup = stateMachineProps.logs.destination as LogGroup; + } + + // Override the defaults with the user provided props + const _smProps = overrideProps(smDefaults.DefaultStateMachineProps(logGroup), stateMachineProps); + + // Override the Cloudwatch permissions to make it more fine grained + const _sm = new sfn.StateMachine(scope, 'StateMachine', _smProps); + const role = _sm.node.findChild('Role') as iam.Role; + const cfnDefaultPolicy = role.node.findChild('DefaultPolicy').node.defaultChild as iam.CfnPolicy; + + // Reduce the scope of actions for the existing DefaultPolicy + cfnDefaultPolicy.addPropertyOverride('PolicyDocument.Statement.0.Action', + [ + "logs:CreateLogDelivery", + 'logs:GetLogDelivery', + 'logs:UpdateLogDelivery', + 'logs:DeleteLogDelivery', + 'logs:ListLogDeliveries' + ]); + + // Override Cfn Nag warning W12: IAM policy should not allow * resource + cfnDefaultPolicy.cfnOptions.metadata = { + cfn_nag: { + rules_to_suppress: [{ + id: 'W12', + reason: `The 'LogDelivery' actions do not support resource-level authorizations` + }] + } + }; + + // Add a new policy with logging permissions for the given cloudwatch log group + _sm.addToRolePolicy(new iam.PolicyStatement({ + actions: [ + 'logs:PutResourcePolicy', + 'logs:DescribeResourcePolicies', + 'logs:DescribeLogGroups' + ], + resources: [`arn:aws:logs:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:*`] + })); + + return _sm; +} + +export function buildStepFunctionCWAlarms(scope: cdk.Construct, sm: sfn.StateMachine): cloudwatch.Alarm[] { + // Setup CW Alarms for State Machine + const alarms: cloudwatch.Alarm[] = new Array(); + + // Sum of number of executions that failed is >= 1 for 5 minutes, 1 consecutive time + alarms.push(new cloudwatch.Alarm(scope, 'ExecutionFailedAlarm', { + metric: sm.metricFailed(), + threshold: 1, + evaluationPeriods: 1, + statistic: 'Sum', + period: cdk.Duration.seconds(300), + comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, + alarmDescription: 'Alarm for the number of executions that failed exceeded the threshold of 1. ' + })); + + // Sum of number of executions that failed maximum is >= 1 for 5 minute, 1 consecutive time + alarms.push(new cloudwatch.Alarm(scope, 'ExecutionThrottledAlarm', { + metric: sm.metricThrottled(), + threshold: 1, + evaluationPeriods: 1, + statistic: 'Sum', + period: cdk.Duration.seconds(300), + comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, + alarmDescription: 'Alarm for the number of executions that throttled exceeded the threshold of 1. ' + })); + + // Number of executions that aborted maximum is >= 1 for 5 minute, 1 consecutive time + alarms.push(new cloudwatch.Alarm(scope, 'ExecutionAbortedAlarm', { + metric: sm.metricAborted(), + threshold: 1, + evaluationPeriods: 1, + statistic: 'Maximum', + period: cdk.Duration.seconds(300), + comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, + alarmDescription: 'Alarm for the number of executions that aborted exceeded the threshold of 1. ' + })); + + return alarms; +} \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/lib/utils.ts b/source/patterns/@aws-solutions-constructs/core/lib/utils.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/lib/utils.ts rename to source/patterns/@aws-solutions-constructs/core/lib/utils.ts diff --git a/source/patterns/@aws-solutions-constructs/core/package.json b/source/patterns/@aws-solutions-constructs/core/package.json new file mode 100644 index 000000000..a0900039c --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/package.json @@ -0,0 +1,122 @@ +{ + "name": "@aws-solutions-constructs/core", + "version": "1.46.0", + "description": "Core CDK Construct for patterns library", + "main": "index.js", + "types": "index.ts", + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/core" + }, + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "scripts": { + "build": "tsc -b .", + "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", + "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", + "test": "jest --coverage", + "clean": "tsc -b --clean", + "watch": "tsc -b -w", + "integ": "cdk-integ", + "integ-assert": "cdk-integ-assert", + "jsii": "jsii", + "jsii-pacmak": "jsii-pacmak", + "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", + "snapshot-update": "npm test -- -u" + }, + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awsconstructs.services.core", + "maven": { + "groupId": "software.amazon.awsconstructs", + "artifactId": "core" + } + }, + "dotnet": { + "namespace": "Amazon.Constructs", + "packageId": "Amazon.Constructs", + "signAssembly": true, + "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" + }, + "python": { + "distName": "aws-solutions-constructs.core", + "module": "aws_solutions_constructs.core" + } + } + }, + "dependencies": { + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kinesisanalytics": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-cdk/aws-stepfunctions": "~1.46.0", + "@types/deep-diff": "^1.0.0", + "@types/npmlog": "^4.1.2", + "deep-diff": "^1.0.2", + "deepmerge": "^4.0.0", + "npmlog": "^4.1.2" + }, + "devDependencies": { + "@aws-cdk/assert": "~1.46.0", + "@types/jest": "^24.0.23", + "@types/node": "^10.3.0" + }, + "jest": { + "moduleFileExtensions": [ + "js" + ] + }, + "bundledDependencies": [ + "deepmerge", + "npmlog", + "@types/npmlog", + "deep-diff", + "@types/deep-diff" + ], + "peerDependencies": { + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-cdk/aws-iot": "~1.46.0", + "@aws-cdk/aws-kinesis": "~1.46.0", + "@aws-cdk/aws-kinesisanalytics": "~1.46.0", + "@aws-cdk/aws-kinesisfirehose": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-lambda-event-sources": "~1.46.0", + "@aws-cdk/aws-logs": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/aws-sns": "~1.46.0", + "@aws-cdk/aws-sqs": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-kms": "~1.46.0", + "@aws-cdk/aws-events": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-elasticsearch": "~1.46.0", + "@aws-cdk/aws-cloudwatch": "~1.46.0", + "@aws-cdk/aws-stepfunctions": "~1.46.0" + } +} diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/apigateway-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/apigateway-helper.test.js.snap similarity index 99% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/apigateway-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/apigateway-helper.test.js.snap index 7a58809aa..5c3ab8940 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/apigateway-helper.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/apigateway-helper.test.js.snap @@ -1079,7 +1079,7 @@ Object { Object { "Ref": "LambdaRestApiDeploymentStageprodB1F3862A", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -1116,7 +1116,7 @@ Object { Object { "Ref": "LambdaRestApi95870433", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap similarity index 99% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap index e2e39f30f..f828e33e3 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudfront-distribution-api-gateway-helper.test.js.snap @@ -562,7 +562,7 @@ Object { Object { "Ref": "RestApiDeploymentStageprod3855DE66", }, - "/*/{proxy+}", + "/*/*", ], ], }, @@ -599,7 +599,7 @@ Object { Object { "Ref": "RestApi0C43BF4B", }, - "/test-invoke-stage/*/{proxy+}", + "/test-invoke-stage/*/*", ], ], }, diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudfront-distribution-s3-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudfront-distribution-s3-helper.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudfront-distribution-s3-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudfront-distribution-s3-helper.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudwatch-log-group.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudwatch-log-group.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/cloudwatch-log-group.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/cloudwatch-log-group.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/congnito-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/congnito-helper.test.js.snap similarity index 83% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/congnito-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/congnito-helper.test.js.snap index 197bb90a9..9310bec1d 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/congnito-helper.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/congnito-helper.test.js.snap @@ -5,6 +5,18 @@ Object { "Resources": Object { "CognitoUserPool53E37E69": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, @@ -88,6 +100,18 @@ Object { "Resources": Object { "CognitoUserPool53E37E69": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, @@ -117,6 +141,24 @@ Object { }, "CognitoUserPoolClient5AB59AE4": Object { "Properties": Object { + "AllowedOAuthFlows": Array [ + "implicit", + "code", + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": Array [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin", + ], + "CallbackURLs": Array [ + "https://example.com", + ], + "SupportedIdentityProviders": Array [ + "COGNITO", + ], "UserPoolId": Object { "Ref": "CognitoUserPool53E37E69", }, diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/dynamo-table.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/dynamo-table.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/dynamo-table.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/dynamo-table.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/elasticsearch-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/elasticsearch-helper.test.js.snap similarity index 93% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/elasticsearch-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/elasticsearch-helper.test.js.snap index 71d02185f..3d223289d 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/elasticsearch-helper.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/elasticsearch-helper.test.js.snap @@ -190,6 +190,18 @@ Object { }, "CognitoUserPool53E37E69": Object { "Properties": Object { + "AccountRecoverySetting": Object { + "RecoveryMechanisms": Array [ + Object { + "Name": "verified_phone_number", + "Priority": 1, + }, + Object { + "Name": "verified_email", + "Priority": 2, + }, + ], + }, "AdminCreateUserConfig": Object { "AllowAdminCreateUserOnly": true, }, @@ -219,7 +231,25 @@ Object { }, "CognitoUserPoolClient5AB59AE4": Object { "Properties": Object { + "AllowedOAuthFlows": Array [ + "implicit", + "code", + ], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": Array [ + "profile", + "phone", + "email", + "openid", + "aws.cognito.signin.user.admin", + ], + "CallbackURLs": Array [ + "https://example.com", + ], "ClientName": "test", + "SupportedIdentityProviders": Array [ + "COGNITO", + ], "UserPoolId": Object { "Ref": "CognitoUserPool53E37E69", }, diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/events-rule.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/events-rule.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/events-rule.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/events-rule.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/iot-rule.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/iot-rule.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/iot-rule.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/iot-rule.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-analytics-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-analytics-helper.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-analytics-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-analytics-helper.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-analytics.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-analytics.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-analytics.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-analytics.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-firehose-s3-defaults.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-firehose-s3-defaults.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-firehose-s3-defaults.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-firehose-s3-defaults.test.js.snap diff --git a/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap new file mode 100644 index 000000000..0a475c44c --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot test kinesisstream default params 1`] = ` +Object { + "Resources": Object { + "KinesisStream46752A3E": Object { + "Properties": Object { + "RetentionPeriodHours": 24, + "ShardCount": 1, + "StreamEncryption": Object { + "EncryptionType": "KMS", + "KeyId": "alias/aws/kinesis", + }, + }, + "Type": "AWS::Kinesis::Stream", + }, + }, +} +`; diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-helper.test.js.snap similarity index 75% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-helper.test.js.snap index 16e052c13..2d4e6783b 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-defaults.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kinesis-streams-helper.test.js.snap @@ -1,28 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`snapshot test kinesisstream default params 1`] = ` +exports[`Test deployment w/ custom properties 1`] = ` Object { "Resources": Object { - "KinesisStream46752A3E": Object { - "Properties": Object { - "RetentionPeriodHours": 24, - "ShardCount": 1, - "StreamEncryption": Object { - "EncryptionType": "KMS", - "KeyId": Object { - "Fn::GetAtt": Array [ - "KinesisStreamKey72E22A02", - "Arn", - ], - }, - }, - }, - "Type": "AWS::Kinesis::Stream", - }, - "KinesisStreamKey72E22A02": Object { + "EncryptionKey1B843E66": Object { "DeletionPolicy": "Retain", "Properties": Object { - "Description": "Created by KinesisStream", + "EnableKeyRotation": true, "KeyPolicy": Object { "Statement": Array [ Object { @@ -71,6 +55,41 @@ Object { "Type": "AWS::KMS::Key", "UpdateReplacePolicy": "Retain", }, + "KinesisStream46752A3E": Object { + "Properties": Object { + "Name": "myCustomKinesisStream", + "RetentionPeriodHours": 24, + "ShardCount": 1, + "StreamEncryption": Object { + "EncryptionType": "KMS", + "KeyId": Object { + "Fn::GetAtt": Array [ + "EncryptionKey1B843E66", + "Arn", + ], + }, + }, + }, + "Type": "AWS::Kinesis::Stream", + }, + }, +} +`; + +exports[`Test minimal deployment with no properties 1`] = ` +Object { + "Resources": Object { + "KinesisStream46752A3E": Object { + "Properties": Object { + "RetentionPeriodHours": 24, + "ShardCount": 1, + "StreamEncryption": Object { + "EncryptionType": "KMS", + "KeyId": "alias/aws/kinesis", + }, + }, + "Type": "AWS::Kinesis::Stream", + }, }, } `; diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kms-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kms-helper.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kms-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/kms-helper.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/lambda-func.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/lambda-func.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/lambda-func.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/lambda-func.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/s3-bucket-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/s3-bucket-helper.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/s3-bucket-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/s3-bucket-helper.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/s3-bucket.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/s3-bucket.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/s3-bucket.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/s3-bucket.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/sns-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/sns-helper.test.js.snap similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/sns-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/sns-helper.test.js.snap diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/sqs-helper.test.js.snap similarity index 76% rename from source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-helper.test.js.snap rename to source/patterns/@aws-solutions-constructs/core/test/__snapshots__/sqs-helper.test.js.snap index add414770..36e4ae13d 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/kinesis-streams-helper.test.js.snap +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/sqs-helper.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Test deployment w/ custom properties 1`] = ` +exports[`Test dead letter queue deployment/configuration 1`] = ` Object { "Resources": Object { "EncryptionKey1B843E66": Object { @@ -55,50 +55,43 @@ Object { "Type": "AWS::KMS::Key", "UpdateReplacePolicy": "Retain", }, - "KinesisStream46752A3E": Object { + "deadletterqueueD1EEB012": Object { "Properties": Object { - "Name": "myCustomKinesisStream", - "RetentionPeriodHours": 24, - "ShardCount": 1, - "StreamEncryption": Object { - "EncryptionType": "KMS", - "KeyId": Object { + "KmsMasterKeyId": "alias/aws/sqs", + }, + "Type": "AWS::SQS::Queue", + }, + "primaryqueue045A5712": Object { + "Properties": Object { + "KmsMasterKeyId": Object { + "Fn::GetAtt": Array [ + "EncryptionKey1B843E66", + "Arn", + ], + }, + "RedrivePolicy": Object { + "deadLetterTargetArn": Object { "Fn::GetAtt": Array [ - "EncryptionKey1B843E66", + "deadletterqueueD1EEB012", "Arn", ], }, + "maxReceiveCount": 3, }, }, - "Type": "AWS::Kinesis::Stream", + "Type": "AWS::SQS::Queue", }, }, } `; -exports[`Test minimal deployment with no properties 1`] = ` +exports[`Test deployment w/ custom properties 1`] = ` Object { "Resources": Object { - "KinesisStream46752A3E": Object { - "Properties": Object { - "RetentionPeriodHours": 24, - "ShardCount": 1, - "StreamEncryption": Object { - "EncryptionType": "KMS", - "KeyId": Object { - "Fn::GetAtt": Array [ - "KinesisStreamKey72E22A02", - "Arn", - ], - }, - }, - }, - "Type": "AWS::Kinesis::Stream", - }, - "KinesisStreamKey72E22A02": Object { + "EncryptionKey1B843E66": Object { "DeletionPolicy": "Retain", "Properties": Object { - "Description": "Created by KinesisStream", + "EnableKeyRotation": true, "KeyPolicy": Object { "Statement": Array [ Object { @@ -147,6 +140,30 @@ Object { "Type": "AWS::KMS::Key", "UpdateReplacePolicy": "Retain", }, + "primaryqueue045A5712": Object { + "Properties": Object { + "KmsMasterKeyId": Object { + "Fn::GetAtt": Array [ + "EncryptionKey1B843E66", + "Arn", + ], + }, + }, + "Type": "AWS::SQS::Queue", + }, + }, +} +`; + +exports[`Test minimal deployment with no properties 1`] = ` +Object { + "Resources": Object { + "primaryqueue045A5712": Object { + "Properties": Object { + "KmsMasterKeyId": "alias/aws/sqs", + }, + "Type": "AWS::SQS::Queue", + }, }, } `; diff --git a/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/step-function-helper.test.js.snap b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/step-function-helper.test.js.snap new file mode 100644 index 000000000..dd1b86f5c --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/test/__snapshots__/step-function-helper.test.js.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Test minimal deployment with no properties 1`] = ` +Object { + "Resources": Object { + "StateMachine2E01A3A5": Object { + "DependsOn": Array [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D", + ], + "Properties": Object { + "DefinitionString": "{\\"StartAt\\":\\"StartState\\",\\"States\\":{\\"StartState\\":{\\"Type\\":\\"Pass\\",\\"End\\":true}}}", + "LoggingConfiguration": Object { + "Destinations": Array [ + Object { + "CloudWatchLogsLogGroup": Object { + "LogGroupArn": Object { + "Fn::GetAtt": Array [ + "StateMachineLogGroup15B91BCB", + "Arn", + ], + }, + }, + }, + ], + "Level": "ERROR", + }, + "RoleArn": Object { + "Fn::GetAtt": Array [ + "StateMachineRoleB840431D", + "Arn", + ], + }, + }, + "Type": "AWS::StepFunctions::StateMachine", + }, + "StateMachineLogGroup15B91BCB": Object { + "DeletionPolicy": "Retain", + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + }, + "StateMachineRoleB840431D": Object { + "Properties": Object { + "AssumeRolePolicyDocument": Object { + "Statement": Array [ + Object { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": Object { + "Service": Object { + "Fn::Join": Array [ + "", + Array [ + "states.", + Object { + "Ref": "AWS::Region", + }, + ".amazonaws.com", + ], + ], + }, + }, + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::IAM::Role", + }, + "StateMachineRoleDefaultPolicyDF1E6607": Object { + "Metadata": Object { + "cfn_nag": Object { + "rules_to_suppress": Array [ + Object { + "id": "W12", + "reason": "The 'LogDelivery' actions do not support resource-level authorizations", + }, + ], + }, + }, + "Properties": Object { + "PolicyDocument": Object { + "Statement": Array [ + Object { + "Action": Array [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + ], + "Effect": "Allow", + "Resource": "*", + }, + Object { + "Action": Array [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups", + ], + "Effect": "Allow", + "Resource": Object { + "Fn::Join": Array [ + "", + Array [ + "arn:aws:logs:", + Object { + "Ref": "AWS::Region", + }, + ":", + Object { + "Ref": "AWS::AccountId", + }, + ":*", + ], + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": Array [ + Object { + "Ref": "StateMachineRoleB840431D", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + }, +} +`; diff --git a/source/patterns/@aws-solutions-konstruk/core/test/apigateway-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/apigateway-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/apigateway-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/cloudfront-distribution-api-gateway-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/cloudfront-distribution-api-gateway-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-api-gateway-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/cloudfront-distribution-s3-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/cloudfront-distribution-s3-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/cloudwatch-log-group.test.ts b/source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/cloudwatch-log-group.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/cloudwatch-log-group.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/congnito-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/congnito-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/congnito-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/dynamo-table.test.ts b/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/dynamo-table.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/elasticsearch-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/elasticsearch-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/elasticsearch-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/events-rule.test.ts b/source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/events-rule.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/events-rule.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/iot-rule.test.ts b/source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/iot-rule.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/iot-rule.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-analytics-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/kinesis-analytics-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-analytics.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/kinesis-analytics.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kinesis-analytics.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-firehose-s3-defaults.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/kinesis-firehose-s3-defaults.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kinesis-firehose-s3-defaults.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-streams-defaults.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/kinesis-streams-defaults.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-defaults.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-streams-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts similarity index 92% rename from source/patterns/@aws-solutions-konstruk/core/test/kinesis-streams-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts index 94bfe492d..5405b43a8 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/kinesis-streams-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/kinesis-streams-helper.test.ts @@ -14,6 +14,7 @@ // Imports import { Stack } from "@aws-cdk/core"; import * as defaults from '../'; +import * as kinesis from '@aws-cdk/aws-kinesis'; import { SynthUtils, ResourcePart } from '@aws-cdk/assert'; import '@aws-cdk/assert/jest'; @@ -48,9 +49,10 @@ test('Test deployment w/ custom properties', () => { const encKey = defaults.buildEncryptionKey(stack); // Helper declaration defaults.buildKinesisStream(stack, { - encryptionKey: encKey, kinesisStreamProps: { - streamName: 'myCustomKinesisStream' + streamName: 'myCustomKinesisStream', + encryption: kinesis.StreamEncryption.KMS, + encryptionKey: encKey } }); // Assertion 1 diff --git a/source/patterns/@aws-solutions-konstruk/core/test/kms-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/kms-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/kms-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/lambda-event-source.test.ts b/source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/lambda-event-source.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/lambda-event-source.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/lambda-func.test.ts b/source/patterns/@aws-solutions-constructs/core/test/lambda-func.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/lambda-func.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/lambda-func.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/lambda-test/index.js b/source/patterns/@aws-solutions-constructs/core/test/lambda-test/index.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/lambda-test/index.js rename to source/patterns/@aws-solutions-constructs/core/test/lambda-test/index.js diff --git a/source/patterns/@aws-solutions-constructs/core/test/lambda/index.js b/source/patterns/@aws-solutions-constructs/core/test/lambda/index.js new file mode 100644 index 000000000..4b3640c1e --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/test/lambda/index.js @@ -0,0 +1,10 @@ +console.log('Loading function'); + +exports.handler = async (event, context) => { + console.log('Received event:', JSON.stringify(event, null, 2)); +    return { +      statusCode: 200, +      headers: { 'Content-Type': 'text/plain' }, +      body: `Hello from Project Vesper! You've hit ${event.path}\n` +    }; +}; \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/core/test/override-warning-service.test.ts b/source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/override-warning-service.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/override-warning-service.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/s3-bucket-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/s3-bucket-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/s3-bucket-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/s3-bucket.test.ts b/source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/s3-bucket.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/s3-bucket.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/sns-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts similarity index 100% rename from source/patterns/@aws-solutions-konstruk/core/test/sns-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/sns-helper.test.ts diff --git a/source/patterns/@aws-solutions-konstruk/core/test/sqs-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts similarity index 88% rename from source/patterns/@aws-solutions-konstruk/core/test/sqs-helper.test.ts rename to source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts index eee43c39e..f53f596ff 100644 --- a/source/patterns/@aws-solutions-konstruk/core/test/sqs-helper.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/sqs-helper.test.ts @@ -16,6 +16,7 @@ import { Stack } from "@aws-cdk/core"; import * as defaults from '../'; import { SynthUtils } from '@aws-cdk/assert'; import '@aws-cdk/assert/jest'; +import * as sqs from '@aws-cdk/aws-sqs'; // -------------------------------------------------------------- // Test minimal deployment with no properties @@ -39,9 +40,10 @@ test('Test deployment w/ custom properties', () => { const encKey = defaults.buildEncryptionKey(stack); // Helper declaration defaults.buildQueue(stack, 'primary-queue', { - encryptionKey: encKey, queueProps: { - description: "custom-queue-props" + description: "custom-queue-props", + encryption: sqs.QueueEncryption.KMS, + encryptionMasterKey: encKey } }); // Assertion 1 @@ -63,9 +65,10 @@ test('Test dead letter queue deployment/configuration', () => { }); // Helper declaration defaults.buildQueue(stack, 'primary-queue', { - encryptionKey: encKey, queueProps: { - description: "not-the-dead-letter-queue-props" + description: "not-the-dead-letter-queue-props", + encryption: sqs.QueueEncryption.KMS, + encryptionMasterKey: encKey }, deadLetterQueue: dlqi }); diff --git a/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts new file mode 100644 index 000000000..72f3e52da --- /dev/null +++ b/source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts @@ -0,0 +1,165 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +// Imports +import { Stack } from "@aws-cdk/core"; +import * as defaults from '../'; +import { SynthUtils } from '@aws-cdk/assert'; +import '@aws-cdk/assert/jest'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import { LogGroup } from "@aws-cdk/aws-logs"; + +// -------------------------------------------------------------- +// Test minimal deployment with no properties +// -------------------------------------------------------------- +test('Test minimal deployment with no properties', () => { + // Stack + const stack = new Stack(); + // Step function definition + const startState = new sfn.Pass(stack, 'StartState'); + // Build state machine + defaults.buildStateMachine(stack, { + definition: startState + }); + // Assertion 1 + expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot(); +}); + +// -------------------------------------------------------------- +// Test deployment w/ custom properties +// -------------------------------------------------------------- +test('Test deployment w/ custom properties', () => { + // Stack + const stack = new Stack(); + // Step function definition + const startState = new sfn.Pass(stack, 'StartState'); + // Build state machine + defaults.buildStateMachine(stack, { + definition: startState, + stateMachineName: 'myStateMachine' + }); + // Assertion + expect(stack).toHaveResource("AWS::StepFunctions::StateMachine", { + StateMachineName: "myStateMachine" + }); +}); + +// -------------------------------------------------------------- +// Test deployment w/ logging enabled +// -------------------------------------------------------------- +test('Test deployment w/ logging enabled', () => { + // Stack + const stack = new Stack(); + // Step function definition + const startState = new sfn.Pass(stack, 'StartState'); + // Log group + const logGroup = new LogGroup(stack, 'myLogGroup', defaults.DefaultLogGroupProps()); + // Build state machine + defaults.buildStateMachine(stack, { + definition: startState, + logs: { + destination: logGroup, + level: sfn.LogLevel.FATAL + } + }); + // Assertion + expect(stack).toHaveResource("AWS::StepFunctions::StateMachine", { + LoggingConfiguration: { + Destinations: [{ + CloudWatchLogsLogGroup: { + LogGroupArn: { + "Fn::GetAtt": [ + "myLogGroup46524CAB", + "Arn" + ] + } + } + }], + Level: 'FATAL' + } + }); +}); + +// -------------------------------------------------------------- +// Check default Cloudwatch perissions +// -------------------------------------------------------------- +test('Test deployment w/ logging enabled', () => { + // Stack + const stack = new Stack(); + // Step function definition + const startState = new sfn.Pass(stack, 'StartState'); + // Build state machine + defaults.buildStateMachine(stack, { + definition: startState + }); + // Assertion + expect(stack).toHaveResource("AWS::IAM::Policy", { + PolicyDocument: { + Statement: [ + { + Action: [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries" + ], + Effect: "Allow", + Resource: "*" + }, + { + Action: [ + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + Effect: "Allow", + Resource: { + "Fn::Join": [ + "", + [ + "arn:aws:logs:", + { + Ref: "AWS::Region" + }, + ":", + { + Ref: "AWS::AccountId" + }, + ":*" + ] + ] + } + } + ], + Version: "2012-10-17" + } + }); +}); + +// -------------------------------------------------------------- +// Check CW Alarms +// -------------------------------------------------------------- +test('Count State Machine CW Alarms', () => { + // Stack + const stack = new Stack(); + // Step function definition + const startState = new sfn.Pass(stack, 'StartState'); + // Build state machine + const sm = defaults.buildStateMachine(stack, { + definition: startState + }); + const cwList = defaults.buildStepFunctionCWAlarms(stack, sm); + + expect(cwList.length).toEqual(3); +}); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-konstruk/eslintrc.yml b/source/patterns/@aws-solutions-constructs/eslintrc.yml similarity index 100% rename from source/patterns/@aws-solutions-konstruk/eslintrc.yml rename to source/patterns/@aws-solutions-constructs/eslintrc.yml diff --git a/source/patterns/@aws-solutions-konstruk/license-header.js b/source/patterns/@aws-solutions-constructs/license-header.js similarity index 100% rename from source/patterns/@aws-solutions-konstruk/license-header.js rename to source/patterns/@aws-solutions-constructs/license-header.js diff --git a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json b/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json deleted file mode 100644 index b7a1a5fa3..000000000 --- a/source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana/package.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana", - "version": "0.8.1", - "description": "CDK Constructs for Amazon Dynamodb stream to AWS Lambda to AWS Elasticsearch with Kibana integration", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "repository": { - "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/aws-dynamodb-stream-lambda-elasticsearch-kibana" - }, - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com", - "organization": true - }, - "license": "Apache-2.0", - "scripts": { - "build": "tsc -b .", - "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", - "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", - "test": "jest --coverage", - "clean": "tsc -b --clean", - "watch": "tsc -b -w", - "integ": "cdk-integ", - "integ-no-clean": "cdk-integ --no-clean", - "integ-assert": "cdk-integ-assert", - "jsii": "jsii", - "jsii-pacmak": "jsii-pacmak", - "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", - "snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" - }, - "jsii": { - "outdir": "dist", - "targets": { - "java": { - "package": "software.amazon.konstruk.services.dynamodbstreamlambdaelasticsearchkibana", - "maven": { - "groupId": "software.amazon.konstruk", - "artifactId": "dynamodbstreamlambdaelasticsearchkibana" - } - }, - "dotnet": { - "namespace": "Amazon.Konstruk.AWS.DynamodbStreamLambdaElasticsearchKibana", - "packageId": "Amazon.Konstruk.AWS.DynamodbStreamLambdaElasticsearchKibana", - "signAssembly": true, - "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" - }, - "python": { - "distName": "aws-solutions-konstruk.aws-dynamodb-stream-lambda-elasticsearch-kibana", - "module": "aws_solutions_konstruk.aws_dynamodb_stream_lambda_elasticsearch_kibana" - } - } - }, - "dependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-dynamodb-stream-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana": "~0.8.1", - "constructs": "^3.0.2" - }, - "devDependencies": { - "@aws-cdk/assert": "~1.40.0", - "@types/jest": "^24.0.23", - "@types/node": "^10.3.0" - }, - "jest": { - "moduleFileExtensions": [ - "js" - ] - }, - "peerDependencies": { - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-solutions-konstruk/aws-dynamodb-stream-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-elasticsearch-kibana": "~0.8.1", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "constructs": "^3.0.2" - } -} diff --git a/source/patterns/@aws-solutions-konstruk/core/README.md b/source/patterns/@aws-solutions-konstruk/core/README.md deleted file mode 100644 index 9ecafd285..000000000 --- a/source/patterns/@aws-solutions-konstruk/core/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# core module - - ---- - -![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) - -> **This is a _developer preview_ (public beta) module.** -> -> All classes are under active development and subject to non-backward compatible changes or removal in any -> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. -> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. - ---- - - -| **API Reference**:| http://docs.awssolutionsbuilder.com/aws-solutions-konstruk/latest/api/core/| -|:-------------|:-------------| -
- -The core library includes the basic building blocks of the AWS Solutions Konstruk Library. It defines the core classes that are used in the rest of the AWS Solutions Konstruk Library. - -## Default Properties for AWS CDK Constructs - -Core library sets the default properties for the AWS CDK Constructs used by the AWS Solutions Konstruk Library constructs. - -For example, the following is the snippet of default properties for S3 Bucket construct created by AWS Solutions Konstruk construct. By default, it will turn on the server-side encryption, bucket versioning, block all public access and setup the S3 access logging. - -``` -{ - encryption: s3.BucketEncryption.S3_MANAGED, - versioned: true, - blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, - removalPolicy: RemovalPolicy.RETAIN, - serverAccessLogsBucket: loggingBucket -} -``` - -## Override the default properties - -The default properties set by the Core library can be overriden by user provided properties. For example, the user can override the Amazon S3 Block Public Access property to meet specific requirements. - -``` - const stack = new cdk.Stack(); - - const props: CloudFrontToS3Props = { - deployBucket: true, - bucketProps: { - blockPublicAccess: { - blockPublicAcls: false, - blockPublicPolicy: true, - ignorePublicAcls: false, - restrictPublicBuckets: true - } - } - }; - - new CloudFrontToS3(stack, 'test-cloudfront-s3', props); - - expect(stack).toHaveResource("AWS::S3::Bucket", { - PublicAccessBlockConfiguration: { - BlockPublicAcls: false, - BlockPublicPolicy: true, - IgnorePublicAcls: false, - RestrictPublicBuckets: true - }, - }); -``` - diff --git a/source/patterns/@aws-solutions-konstruk/core/package.json b/source/patterns/@aws-solutions-konstruk/core/package.json deleted file mode 100644 index 76287da2a..000000000 --- a/source/patterns/@aws-solutions-konstruk/core/package.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - "name": "@aws-solutions-konstruk/core", - "version": "0.8.1", - "description": "Core CDK Construct for patterns library", - "main": "index.js", - "types": "index.ts", - "repository": { - "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", - "directory": "source/patterns/@aws-solutions-konstruk/core" - }, - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com", - "organization": true - }, - "license": "Apache-2.0", - "scripts": { - "build": "tsc -b .", - "lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", - "lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", - "test": "jest --coverage", - "clean": "tsc -b --clean", - "watch": "tsc -b -w", - "integ": "cdk-integ", - "integ-assert": "cdk-integ-assert", - "jsii": "jsii", - "jsii-pacmak": "jsii-pacmak", - "build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", - "snapshot-update": "npm test -- -u" - }, - "jsii": { - "outdir": "dist", - "targets": { - "java": { - "package": "software.amazon.konstruk.services.core", - "maven": { - "groupId": "software.amazon.konstruk", - "artifactId": "core" - } - }, - "dotnet": { - "namespace": "Amazon.Konstruk", - "packageId": "Amazon.Konstruk", - "signAssembly": true, - "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" - }, - "python": { - "distName": "aws-solutions-konstruk.core", - "module": "aws_solutions_konstruk.core" - } - } - }, - "dependencies": { - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kinesisanalytics": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-events": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0", - "@types/deep-diff": "^1.0.0", - "@types/npmlog": "^4.1.2", - "deep-diff": "^1.0.2", - "deepmerge": "^4.0.0", - "npmlog": "^4.1.2" - }, - "devDependencies": { - "@aws-cdk/assert": "~1.40.0", - "@types/jest": "^24.0.23", - "@types/node": "^10.3.0" - }, - "jest": { - "moduleFileExtensions": [ - "js" - ] - }, - "bundledDependencies": [ - "deepmerge", - "npmlog", - "@types/npmlog", - "deep-diff", - "@types/deep-diff" - ], - "peerDependencies": { - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-cdk/aws-iot": "~1.40.0", - "@aws-cdk/aws-kinesis": "~1.40.0", - "@aws-cdk/aws-kinesisanalytics": "~1.40.0", - "@aws-cdk/aws-kinesisfirehose": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-lambda-event-sources": "~1.40.0", - "@aws-cdk/aws-logs": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/aws-sns": "~1.40.0", - "@aws-cdk/aws-sqs": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-kms": "~1.40.0", - "@aws-cdk/aws-events": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-elasticsearch": "~1.40.0", - "@aws-cdk/aws-cloudwatch": "~1.40.0" - } -} diff --git a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/sqs-helper.test.js.snap b/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/sqs-helper.test.js.snap deleted file mode 100644 index 21679a006..000000000 --- a/source/patterns/@aws-solutions-konstruk/core/test/__snapshots__/sqs-helper.test.js.snap +++ /dev/null @@ -1,283 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Test dead letter queue deployment/configuration 1`] = ` -Object { - "Resources": Object { - "EncryptionKey1B843E66": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, - "deadletterqueueD1EEB012": Object { - "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "deadletterqueueKey123D45B8", - "Arn", - ], - }, - }, - "Type": "AWS::SQS::Queue", - }, - "deadletterqueueKey123D45B8": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "Description": "Created by dead-letter-queue", - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, - "primaryqueue045A5712": Object { - "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "EncryptionKey1B843E66", - "Arn", - ], - }, - "RedrivePolicy": Object { - "deadLetterTargetArn": Object { - "Fn::GetAtt": Array [ - "deadletterqueueD1EEB012", - "Arn", - ], - }, - "maxReceiveCount": 3, - }, - }, - "Type": "AWS::SQS::Queue", - }, - }, -} -`; - -exports[`Test deployment w/ custom properties 1`] = ` -Object { - "Resources": Object { - "EncryptionKey1B843E66": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "EnableKeyRotation": true, - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, - "primaryqueue045A5712": Object { - "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "EncryptionKey1B843E66", - "Arn", - ], - }, - }, - "Type": "AWS::SQS::Queue", - }, - }, -} -`; - -exports[`Test minimal deployment with no properties 1`] = ` -Object { - "Resources": Object { - "primaryqueue045A5712": Object { - "Properties": Object { - "KmsMasterKeyId": Object { - "Fn::GetAtt": Array [ - "primaryqueueKeyD3CAD16D", - "Arn", - ], - }, - }, - "Type": "AWS::SQS::Queue", - }, - "primaryqueueKeyD3CAD16D": Object { - "DeletionPolicy": "Retain", - "Properties": Object { - "Description": "Created by primary-queue", - "KeyPolicy": Object { - "Statement": Array [ - Object { - "Action": Array [ - "kms:Create*", - "kms:Describe*", - "kms:Enable*", - "kms:List*", - "kms:Put*", - "kms:Update*", - "kms:Revoke*", - "kms:Disable*", - "kms:Get*", - "kms:Delete*", - "kms:ScheduleKeyDeletion", - "kms:CancelKeyDeletion", - "kms:GenerateDataKey", - "kms:TagResource", - "kms:UntagResource", - ], - "Effect": "Allow", - "Principal": Object { - "AWS": Object { - "Fn::Join": Array [ - "", - Array [ - "arn:", - Object { - "Ref": "AWS::Partition", - }, - ":iam::", - Object { - "Ref": "AWS::AccountId", - }, - ":root", - ], - ], - }, - }, - "Resource": "*", - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::KMS::Key", - "UpdateReplacePolicy": "Retain", - }, - }, -} -`; diff --git a/source/tools/cdk-integ-tools/package.json b/source/tools/cdk-integ-tools/package.json index 9ec2c34e8..7f7eb4205 100644 --- a/source/tools/cdk-integ-tools/package.json +++ b/source/tools/cdk-integ-tools/package.json @@ -31,9 +31,9 @@ "typescript": "~3.7.4" }, "dependencies": { - "@aws-cdk/cloudformation-diff": "1.40.0", - "@aws-cdk/cx-api": "1.40.0", - "aws-cdk": "1.40.0", + "@aws-cdk/cloudformation-diff": "~1.46.0", + "@aws-cdk/cx-api": "~1.46.0", + "aws-cdk": "~1.46.0", "fs-extra": "^8.1.0", "yargs": "^15.1.0" }, diff --git a/source/use_cases/aws-s3-static-website/architecture.png b/source/use_cases/aws-s3-static-website/architecture.png index 967bc554f..54436bdf5 100644 Binary files a/source/use_cases/aws-s3-static-website/architecture.png and b/source/use_cases/aws-s3-static-website/architecture.png differ diff --git a/source/use_cases/aws-s3-static-website/lib/s3-static-site-stack.ts b/source/use_cases/aws-s3-static-website/lib/s3-static-site-stack.ts index a3df7e9fc..27c3fffc8 100644 --- a/source/use_cases/aws-s3-static-website/lib/s3-static-site-stack.ts +++ b/source/use_cases/aws-s3-static-website/lib/s3-static-site-stack.ts @@ -12,7 +12,7 @@ */ import { Construct, Stack, StackProps, Duration, CfnOutput } from '@aws-cdk/core'; -import { CloudFrontToS3 } from '@aws-solutions-konstruk/aws-cloudfront-s3'; +import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3'; import * as lambda from '@aws-cdk/aws-lambda'; import { Provider } from '@aws-cdk/custom-resources'; import { CustomResource } from '@aws-cdk/aws-cloudformation'; @@ -25,10 +25,10 @@ export class S3StaticWebsiteStack extends Stack { const sourceBucket: string = 'wildrydes-us-east-1'; const sourcePrefix: string = 'WebApplication/1_StaticWebHosting/website/'; - const konstruk = new CloudFrontToS3(this, 'CloudFrontToS3', { + const construct = new CloudFrontToS3(this, 'CloudFrontToS3', { deployBucket: true }); - const targetBucket: string = konstruk.bucket().bucketName; + const targetBucket: string = construct.s3Bucket.bucketName; const lambdaFunc = new lambda.Function(this, 'copyObjHandler', { runtime: lambda.Runtime.PYTHON_3_8, @@ -71,7 +71,7 @@ export class S3StaticWebsiteStack extends Stack { }); new CfnOutput(this, 'websiteURL', { - value: 'https://' + konstruk.cloudFrontWebDistribution().domainName + value: 'https://' + construct.cloudFrontWebDistribution.domainName }); } } \ No newline at end of file diff --git a/source/use_cases/aws-s3-static-website/package.json b/source/use_cases/aws-s3-static-website/package.json index da341c72f..dd28068c4 100644 --- a/source/use_cases/aws-s3-static-website/package.json +++ b/source/use_cases/aws-s3-static-website/package.json @@ -1,12 +1,12 @@ { - "name": "@aws-solutions-konstruk/aws-s3-static-website", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-s3-static-website", + "version": "1.46.0", "description": "Use case pattern for deploying a S3 static website.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", "directory": "source/use_cases/aws-s3-static-website" }, "author": { @@ -28,19 +28,19 @@ "build+lint+test": "npm run build && npm run lint && npm test && npm run integ-assert" }, "dependencies": { - "@aws-solutions-konstruk/aws-cloudfront-s3": "~0.8.1", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/custom-resources": "~1.40.0", - "@aws-cdk/aws-cloudformation": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-solutions-constructs/aws-cloudfront-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/custom-resources": "~1.46.0", + "@aws-cdk/aws-cloudformation": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "source-map-support": "^0.5.16" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, diff --git a/source/use_cases/aws-serverless-image-handler/README.md b/source/use_cases/aws-serverless-image-handler/README.md index b350f4013..fc092ca78 100644 --- a/source/use_cases/aws-serverless-image-handler/README.md +++ b/source/use_cases/aws-serverless-image-handler/README.md @@ -7,7 +7,7 @@ one or more Amazon S3 buckets within the deployment account. Here is a minimal deployable pattern definition: ``` -const { ServerlessImageHandler } = require('@aws-konstruk/aws-serverless-image-handler'); +const { ServerlessImageHandler } = require('@aws-solutions-constructs/aws-serverless-image-handler'); new ServerlessImageHandler(stack, 'ServerlessImageHandlerPattern', { deployLambda: true, diff --git a/source/use_cases/aws-serverless-image-handler/lib/index.ts b/source/use_cases/aws-serverless-image-handler/lib/index.ts index 9047fd8c5..441a91fef 100644 --- a/source/use_cases/aws-serverless-image-handler/lib/index.ts +++ b/source/use_cases/aws-serverless-image-handler/lib/index.ts @@ -12,15 +12,15 @@ */ // Imports -import * as defaults from '@aws-solutions-konstruk/core'; +import * as defaults from '@aws-solutions-constructs/core'; import { Construct } from '@aws-cdk/core'; import * as cloudFront from '@aws-cdk/aws-cloudfront'; import * as apiGateway from '@aws-cdk/aws-apigateway'; import * as lambda from '@aws-cdk/aws-lambda'; import * as iam from '@aws-cdk/aws-iam'; import * as s3 from '@aws-cdk/aws-s3'; -import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda'; -import { LambdaToS3 } from '@aws-solutions-konstruk/aws-lambda-s3'; +import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda'; +import { LambdaToS3 } from '@aws-solutions-constructs/aws-lambda-s3'; /** * The properties for the ServerlessImageHandler class. @@ -151,7 +151,7 @@ export class ServerlessImageHandler extends Construct { deployLambda: true, lambdaFunctionProps: functionProps }); - const existingLambdaFn = this.cloudFrontApiGatewayLambda.lambdaFunction(); + const existingLambdaFn = this.cloudFrontApiGatewayLambda.lambdaFunction; // Build the LambdaToS3 pattern this.lambdaS3 = new LambdaToS3(this, 'ExistingLambdaS3', { @@ -196,9 +196,9 @@ export class ServerlessImageHandler extends Construct { // Add the SOURCE_BUCKETS environment variable to the Lambda function const bucketsArr = (props.sourceBuckets !== "") ? props.sourceBuckets.split(',') : []; - bucketsArr.push(this.lambdaS3.s3Bucket().bucketName); + bucketsArr.push(this.lambdaS3.s3Bucket.bucketName); const bucketsStr = bucketsArr.toString().replace(/\s+/g, ''); - this.cloudFrontApiGatewayLambda.lambdaFunction().addEnvironment("SOURCE_BUCKETS", bucketsStr); + this.cloudFrontApiGatewayLambda.lambdaFunction.addEnvironment("SOURCE_BUCKETS", bucketsStr); } /** @@ -208,7 +208,7 @@ export class ServerlessImageHandler extends Construct { * @access public */ public cloudFrontDistribution(): cloudFront.CloudFrontWebDistribution { - return this.cloudFrontApiGatewayLambda.cloudFrontWebDistribution(); + return this.cloudFrontApiGatewayLambda.cloudFrontWebDistribution; } /** @@ -218,7 +218,7 @@ export class ServerlessImageHandler extends Construct { * @access public */ public apiGateway(): apiGateway.RestApi { - return this.cloudFrontApiGatewayLambda.restApi(); + return this.cloudFrontApiGatewayLambda.apiGateway; } /** @@ -228,7 +228,7 @@ export class ServerlessImageHandler extends Construct { * @access public */ public lambdaFunction(): lambda.Function { - return this.cloudFrontApiGatewayLambda.lambdaFunction(); + return this.cloudFrontApiGatewayLambda.lambdaFunction; } /** @@ -238,6 +238,6 @@ export class ServerlessImageHandler extends Construct { * @access public */ public s3Bucket(): s3.Bucket { - return this.lambdaS3.s3Bucket(); + return this.lambdaS3.s3Bucket; } } \ No newline at end of file diff --git a/source/use_cases/aws-serverless-image-handler/package.json b/source/use_cases/aws-serverless-image-handler/package.json index b63cb890d..de03059fc 100644 --- a/source/use_cases/aws-serverless-image-handler/package.json +++ b/source/use_cases/aws-serverless-image-handler/package.json @@ -1,13 +1,13 @@ { - "name": "@aws-konstruk/aws-serverless-image-handler", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-serverless-image-handler", + "version": "1.46.0", "description": "Use case pattern for deploying a serverless image handler API.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-konstruk.git", - "directory": "source/patterns/@aws-konstruk/aws-serverless-image-handler" + "url": "https://github.com/awslabs/aws-solutions-constructs.git", + "directory": "source/patterns/@aws-solutions-constructs/aws-serverless-image-handler" }, "author": { "name": "Amazon Web Services", @@ -34,37 +34,37 @@ "outdir": "dist", "targets": { "java": { - "package": "software.amazon.konstruk.services.serverlessimagehandler", + "package": "software.amazon.awsconstructs.services.serverlessimagehandler", "maven": { - "groupId": "software.amazon.konstruk", + "groupId": "software.amazon.awsconstructs", "artifactId": "serverlessimagehandler" } }, "dotnet": { - "namespace": "Amazon.Konstruk.AWS.ServerlessImageHandler", - "packageId": "Amazon.Konstruk.AWS.ServerlessImageHandler", + "namespace": "Amazon.Constructs.AWS.ServerlessImageHandler", + "packageId": "Amazon.Constructs.AWS.ServerlessImageHandler", "signAssembly": true, "iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" }, "python": { - "distName": "aws-konstruk.aws-serverless-image-handler", - "module": "aws_konstruk.aws_serverless_image_handler" + "distName": "aws-solutions-constructs.aws-serverless-image-handler", + "module": "aws_solutions_constructs.aws_serverless_image_handler" } } }, "dependencies": { - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/core": "~1.40.0", - "@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-s3": "~0.8.1", - "@aws-solutions-konstruk/core": "~0.8.1" + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-solutions-constructs/aws-cloudfront-apigateway-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" }, @@ -74,14 +74,14 @@ ] }, "peerDependencies": { - "@aws-solutions-konstruk/aws-cloudfront-apigateway-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-s3": "~0.8.1", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", - "@aws-cdk/aws-iam": "~1.40.0" + "@aws-solutions-constructs/aws-cloudfront-apigateway-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-s3": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0" } } diff --git a/source/use_cases/aws-serverless-web-app/lib/s3-static-site-stack.ts b/source/use_cases/aws-serverless-web-app/lib/s3-static-site-stack.ts index 646f28893..1299caa2b 100644 --- a/source/use_cases/aws-serverless-web-app/lib/s3-static-site-stack.ts +++ b/source/use_cases/aws-serverless-web-app/lib/s3-static-site-stack.ts @@ -12,7 +12,7 @@ */ import { Construct, Stack, StackProps, Duration, CfnOutput } from '@aws-cdk/core'; -import { CloudFrontToS3 } from '@aws-solutions-konstruk/aws-cloudfront-s3'; +import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3'; import * as lambda from '@aws-cdk/aws-lambda'; import { Provider } from '@aws-cdk/custom-resources'; import { CustomResource } from '@aws-cdk/aws-cloudformation'; @@ -25,10 +25,10 @@ export class S3StaticWebsiteStack extends Stack { const sourceBucket: string = 'wildrydes-us-east-1'; const sourcePrefix: string = 'WebApplication/1_StaticWebHosting/website/'; - const konstruk = new CloudFrontToS3(this, 'CloudFrontToS3', { + const construct = new CloudFrontToS3(this, 'CloudFrontToS3', { deployBucket: true }); - const targetBucket: string = konstruk.bucket().bucketName; + const targetBucket: string = construct.s3Bucket.bucketName; const lambdaFunc = new lambda.Function(this, 'staticContentHandler', { runtime: lambda.Runtime.PYTHON_3_8, @@ -71,7 +71,7 @@ export class S3StaticWebsiteStack extends Stack { }); new CfnOutput(this, 'websiteURL', { - value: 'https://' + konstruk.cloudFrontWebDistribution().domainName + value: 'https://' + construct.cloudFrontWebDistribution.domainName }); new CfnOutput(this, 'websiteBucket', { diff --git a/source/use_cases/aws-serverless-web-app/lib/serverless-backend-stack.ts b/source/use_cases/aws-serverless-web-app/lib/serverless-backend-stack.ts index 70b57f305..3afa348b5 100644 --- a/source/use_cases/aws-serverless-web-app/lib/serverless-backend-stack.ts +++ b/source/use_cases/aws-serverless-web-app/lib/serverless-backend-stack.ts @@ -11,8 +11,8 @@ * and limitations under the License. */ -import { CognitoToApiGatewayToLambda } from '@aws-solutions-konstruk/aws-cognito-apigateway-lambda'; -import { LambdaToDynamoDB } from '@aws-solutions-konstruk/aws-lambda-dynamodb'; +import { CognitoToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cognito-apigateway-lambda'; +import { LambdaToDynamoDB } from '@aws-solutions-constructs/aws-lambda-dynamodb'; import { Construct, Stack, StackProps, Duration, Fn } from '@aws-cdk/core'; import * as lambda from '@aws-cdk/aws-lambda'; import { Provider } from '@aws-cdk/custom-resources'; @@ -27,7 +27,7 @@ export class ServerlessBackendStack extends Stack { const websiteBucketName: string = Fn.importValue('websiteBucket'); - const konstruk = new CognitoToApiGatewayToLambda(this, 'CognitoToApiGatewayToLambda', { + const construct = new CognitoToApiGatewayToLambda(this, 'CognitoToApiGatewayToLambda', { deployLambda: true, lambdaFunctionProps: { code: lambda.Code.asset(`${__dirname}/lambda/business-logic`), @@ -68,17 +68,17 @@ export class ServerlessBackendStack extends Stack { new CustomResource(this, 'CustomResource', { provider: customResourceProvider, properties: { - UserPool: konstruk.userPool().userPoolId, - Client: konstruk.userPoolClient().userPoolClientId, + UserPool: construct.userPool.userPoolId, + Client: construct.userPoolClient.userPoolClientId, Region: Stack.of(this).region, Bucket: websiteBucketName, - RestApi: konstruk.restApi().url + RestApi: construct.apiGateway.url } }); new LambdaToDynamoDB(this, 'LambdaToDynamoDB', { deployLambda: false, - existingLambdaObj: konstruk.lambdaFunction(), + existingLambdaObj: construct.lambdaFunction, dynamoTableProps: { tableName: 'Rides', partitionKey: { diff --git a/source/use_cases/aws-serverless-web-app/package.json b/source/use_cases/aws-serverless-web-app/package.json index da373f845..7b1a0c10e 100644 --- a/source/use_cases/aws-serverless-web-app/package.json +++ b/source/use_cases/aws-serverless-web-app/package.json @@ -1,12 +1,12 @@ { - "name": "@aws-solutions-konstruk/aws-serverless-web-app", - "version": "0.8.1", + "name": "@aws-solutions-constructs/aws-serverless-web-app", + "version": "1.46.0", "description": "Use case pattern for deploying a serverless web app.", "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/awslabs/aws-solutions-konstruk.git", + "url": "https://github.com/awslabs/aws-solutions-constructs.git", "directory": "source/use_cases/aws-serverless-web-app" }, "author": { @@ -28,24 +28,24 @@ "build+lint+test": "npm run build && npm run lint && npm test && npm run integ-assert" }, "dependencies": { - "@aws-solutions-konstruk/aws-cloudfront-s3": "~0.8.1", - "@aws-solutions-konstruk/aws-cognito-apigateway-lambda": "~0.8.1", - "@aws-solutions-konstruk/aws-lambda-dynamodb": "~0.8.1", - "@aws-cdk/core": "~1.40.0", - "@aws-cdk/aws-lambda": "~1.40.0", - "@aws-cdk/aws-cloudfront": "~1.40.0", - "@aws-cdk/aws-s3": "~1.40.0", - "@aws-cdk/custom-resources": "~1.40.0", - "@aws-cdk/aws-cloudformation": "~1.40.0", - "@aws-cdk/aws-iam": "~1.40.0", - "@aws-cdk/aws-cognito": "~1.40.0", - "@aws-cdk/aws-apigateway": "~1.40.0", - "@aws-cdk/aws-dynamodb": "~1.40.0", - "@aws-solutions-konstruk/core": "~0.8.1", + "@aws-solutions-constructs/aws-cloudfront-s3": "~1.46.0", + "@aws-solutions-constructs/aws-cognito-apigateway-lambda": "~1.46.0", + "@aws-solutions-constructs/aws-lambda-dynamodb": "~1.46.0", + "@aws-cdk/core": "~1.46.0", + "@aws-cdk/aws-lambda": "~1.46.0", + "@aws-cdk/aws-cloudfront": "~1.46.0", + "@aws-cdk/aws-s3": "~1.46.0", + "@aws-cdk/custom-resources": "~1.46.0", + "@aws-cdk/aws-cloudformation": "~1.46.0", + "@aws-cdk/aws-iam": "~1.46.0", + "@aws-cdk/aws-cognito": "~1.46.0", + "@aws-cdk/aws-apigateway": "~1.46.0", + "@aws-cdk/aws-dynamodb": "~1.46.0", + "@aws-solutions-constructs/core": "~1.46.0", "source-map-support": "^0.5.16" }, "devDependencies": { - "@aws-cdk/assert": "~1.40.0", + "@aws-cdk/assert": "~1.46.0", "@types/jest": "^24.0.23", "@types/node": "^10.3.0" },