From 2ecd9dd935b731d2e4705ed9c146efcad0961fd8 Mon Sep 17 00:00:00 2001 From: mickychetta <45010053+mickychetta@users.noreply.github.com> Date: Thu, 31 Mar 2022 13:49:33 -0700 Subject: [PATCH] feat(README.md): add python and java minimal deployment (#582) * added python min deployment and removed initializers * fixed merge conflict * changed to v1 imports in deprecated constructs * added python min dep in new constructs * added java minimal deployment code * fixed java builder prop defintion * fixed indentation * fixed indentation * updated python minimal deployments * updated java minimal deployments * updated to correct prop in route53-apigateway * updated python minimal deployments * cast to type Any in python example * updated java minimal deployments * updated java minimal deployments * updated typescript minimal deployments * added viperlight ignore to README with fake account numbers * added viperlight ignore to README with fake account numbers * added v1 deprecated comments in v1 constructs * changed asset name in aws-lambda-sqs-lambda --- .viperlightignore | 14 ++ .../aws-alb-fargate/README.md | 103 +++++++++--- .../aws-alb-lambda/README.md | 130 ++++++++++---- .../aws-apigateway-dynamodb/README.md | 29 +++- .../aws-apigateway-iot/README.md | 32 ++-- .../aws-apigateway-kinesisstreams/README.md | 32 ++-- .../aws-apigateway-lambda/README.md | 59 +++++-- .../README.md | 94 ++++++++--- .../aws-apigateway-sqs/README.md | 29 +++- .../README.md | 59 +++++-- .../aws-cloudfront-apigateway/README.md | 100 ++++++++--- .../aws-cloudfront-mediastore/README.md | 29 +++- .../aws-cloudfront-s3/README.md | 29 +++- .../aws-cognito-apigateway-lambda/README.md | 137 +++++++++++++-- .../README.md | 71 ++++++-- .../aws-dynamodb-stream-lambda/README.md | 65 +++++-- .../README.md | 70 ++++++-- .../aws-dynamodbstreams-lambda/README.md | 53 ++++-- .../README.md | 52 ++++-- .../aws-eventbridge-kinesisstreams/README.md | 62 ++++--- .../aws-eventbridge-lambda/README.md | 85 +++++++--- .../aws-eventbridge-sns/README.md | 90 +++++++--- .../aws-eventbridge-sqs/README.md | 80 +++++++-- .../aws-eventbridge-stepfunctions/README.md | 79 ++++++--- .../README.md | 53 ++++-- .../aws-events-rule-kinesisstreams/README.md | 59 +++++-- .../aws-events-rule-lambda/README.md | 81 ++++++--- .../aws-events-rule-sns/README.md | 87 +++++++--- .../aws-events-rule-sqs/README.md | 88 +++++++--- .../aws-events-rule-step-function/README.md | 79 +++++++-- .../aws-fargate-s3/README.md | 39 ++++- .../aws-fargate-sns/README.md | 53 +++--- .../aws-fargate-sqs/README.md | 37 +++- .../aws-iot-kinesisfirehose-s3/README.md | 60 +++++-- .../aws-iot-kinesisstreams/README.md | 78 ++++++--- .../aws-iot-lambda-dynamodb/README.md | 103 +++++++++--- .../aws-iot-lambda/README.md | 101 ++++++++--- .../aws-iot-s3/README.md | 78 ++++++--- .../aws-iot-sqs/README.md | 76 ++++++--- .../README.md | 159 +++++++++++++----- .../aws-kinesisfirehose-s3/README.md | 31 ++-- .../aws-kinesisstreams-gluejob/README.md | 15 +- .../README.md | 29 +++- .../aws-kinesisstreams-lambda/README.md | 81 ++++++--- .../aws-lambda-dynamodb/README.md | 68 +++++--- .../aws-lambda-elasticsearch-kibana/README.md | 79 ++++++--- .../aws-lambda-eventbridge/README.md | 61 +++++-- .../aws-lambda-s3/README.md | 52 ++++-- .../aws-lambda-sagemakerendpoint/README.md | 83 +++++++-- .../aws-lambda-secretsmanager/README.md | 72 +++++--- .../aws-lambda-sns/README.md | 61 +++++-- .../aws-lambda-sqs-lambda/README.md | 66 ++++++-- .../aws-lambda-sqs/README.md | 61 +++++-- .../aws-lambda-ssmstringparameter/README.md | 80 ++++++--- .../aws-lambda-step-function/README.md | 76 +++++++-- .../aws-lambda-stepfunctions/README.md | 73 ++++++-- .../aws-route53-alb/README.md | 67 ++++++-- .../aws-route53-apigateway/README.md | 100 +++++++++-- .../aws-s3-lambda/README.md | 57 +++++-- .../aws-s3-sqs/README.md | 32 ++-- .../aws-s3-step-function/README.md | 57 +++++-- .../aws-s3-stepfunctions/README.md | 50 ++++-- .../aws-sns-lambda/README.md | 61 +++++-- .../aws-sns-sqs/README.md | 56 ++++-- .../aws-sqs-lambda/README.md | 57 +++++-- .../aws-wafwebacl-alb/README.md | 83 ++++++--- .../aws-wafwebacl-apigateway/README.md | 80 +++++++-- .../aws-wafwebacl-cloudfront/README.md | 43 ++++- 68 files changed, 3430 insertions(+), 1115 deletions(-) diff --git a/.viperlightignore b/.viperlightignore index c168d5aea..3f9309e54 100644 --- a/.viperlightignore +++ b/.viperlightignore @@ -145,6 +145,16 @@ source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md:35 source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/alb-lambda.test.ts:27 source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/alb-lambda.test.ts:680 # These are references to the us-east-1 ELBV2 account (publicly known) +source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPrivateApi.expected.json:196 +source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPrivateApiExistingZone.expected.json:853 +source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPublicApiNewAlb.expected.json:191 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.privateApiNewResources.expected.json:199 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.publicApiNewResources.expected.json:202 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.twoTargets.expected.json:202 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.privateApiExistingResources.expected.json:1067 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.publicApiExistingResources.expected.json:1067 +source/patterns/@aws-solutions-constructs/aws-alb-fargate/test/integ.all-new-two-targets.expected.json:1034 +source/patterns/@aws-solutions-constructs/aws-alb-fargate/test/integ.all-new-public-http.expected.json:1007 source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPrivateApi.expected.json:242 source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPrivateApiExistingZone.expected.json:899 source/patterns/@aws-solutions-constructs/aws-route53-alb/test/integ.deployPublicApiNewAlb.expected.json:237 @@ -155,3 +165,7 @@ source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.privateApiEx source/patterns/@aws-solutions-constructs/aws-alb-lambda/test/integ.publicApiExistingResources.expected.json:1113 source/patterns/@aws-solutions-constructs/aws-alb-fargate/test/integ.all-new-two-targets.expected.json:1081 source/patterns/@aws-solutions-constructs/aws-alb-fargate/test/integ.all-new-public-http.expected.json:1054 +source/patterns/@aws-solutions-constructs/aws-alb-fargate/README.md:78 +source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md:84 +source/patterns/@aws-solutions-constructs/aws-route53-alb/README.md:59 +source/patterns/@aws-solutions-constructs/aws-wafwebacl-alb/README.md:68 diff --git a/source/patterns/@aws-solutions-constructs/aws-alb-fargate/README.md b/source/patterns/@aws-solutions-constructs/aws-alb-fargate/README.md index 9ec754c03..8b979c0a0 100644 --- a/source/patterns/@aws-solutions-constructs/aws-alb-fargate/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-alb-fargate/README.md @@ -24,41 +24,100 @@ This AWS Solutions Construct implements an an Application Load Balancer to an AWS Fargate service -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript - import { AlbToFargate, AlbToFargateProps } from '@aws-solutions-constructs/aws-alb-fargate'; - - // Obtain a pre-existing certificate from your account - const certificate = acm.Certificate.fromCertificateArn( - scope, - 'existing-cert', - "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" - ); - - const props: AlbToFargateProps = { +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { AlbToFargate, AlbToFargateProps } from '@aws-solutions-constructs/aws-alb-fargate'; +import * as acm from 'aws-cdk-lib/aws-certificatemanager'; + +const certificate = acm.Certificate.fromCertificateArn( + this, + 'existing-cert', + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" +); + +const constructProps: AlbToFargateProps = { ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo", ecrImageVersion: "latest", listenerProps: { - certificates: [ certificate ] + certificates: [certificate] }, publicApi: true - }; +}; - new AlbToFargate(stack, 'new-construct', props); +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, 'id', {env: {account: '123456789012', region: 'us-east-1' }}); +new AlbToFargate(this, 'new-construct', constructProps); ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_alb_fargate import AlbToFargate, AlbToFargateProps +from aws_cdk import ( + aws_certificatemanager as acm, + aws_elasticloadbalancingv2 as alb, + Stack +) +from constructs import Construct + +# Obtain a pre-existing certificate from your account +certificate = acm.Certificate.from_certificate_arn( + self, + 'existing-cert', + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" + ) + +# Note - all alb constructs turn on ELB logging by default, so require that an environment including account +# and region be provided when creating the stack +# +# MyStack(app, 'id', env=cdk.Environment(account='679431688440', region='us-east-1')) +AlbToFargate(self, 'new-construct', + ecr_repository_arn="arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo", + ecr_image_version="latest", + listener_props=alb.BaseApplicationListenerProps( + certificates=[certificate], + ), + public_api=True) -``` text -new AlbToFargate(scope: Construct, id: string, props: AlbToFargateProps); ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`AlbToFargateProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.elasticloadbalancingv2.*; +import software.amazon.awsconstructs.services.albfargate.*; + +// The code that defines your stack goes here +// Obtain a pre-existing certificate from your account +ListenerCertificate listenerCertificate = ListenerCertificate + .fromArn("arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012"); + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, "id", StackProps.builder() +// .env(Environment.builder() +// .account("123456789012") +// .region("us-east-1") +// .build()); +new AlbToFargate(this, "AlbToFargatePattern", new AlbToFargateProps.Builder() + .ecrRepositoryArn("arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") + .ecrImageVersion("latest") + .listenerProps(new BaseApplicationListenerProps.Builder() + .certificates(List.of(listenerCertificate)) + .build()) + .publicApi(true) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md index 4a18c6c8c..98b723ca7 100644 --- a/source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-alb-lambda/README.md @@ -24,42 +24,112 @@ This AWS Solutions Construct implements an an Application Load Balancer to an AWS Lambda function -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript - - // Obtain a pre-existing certificate from your account - const certificate = acm.Certificate.fromCertificateArn( - scope, - 'existing-cert', - "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" - ); - const props: AlbToLambdaProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, - listenerProps: { - certificates: [ certificate ] - }, - publicApi: true - }; - new AlbToLambda(stack, 'new-construct', props); - +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { AlbToLambda, AlbToLambdaProps } from '@aws-solutions-constructs/aws-alb-lambda'; +import * as acm from 'aws-cdk-lib/aws-certificatemanager'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +// Obtain a pre-existing certificate from your account +const certificate = acm.Certificate.fromCertificateArn( + this, + 'existing-cert', + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" +); + +const constructProps: AlbToLambdaProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, + listenerProps: { + certificates: [certificate] + }, + publicApi: true +}; + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, 'id', {env: {account: '123456789012', region: 'us-east-1' }}); +new AlbToLambda(this, 'new-construct', constructProps); ``` -## Initializer - -``` text -new AlbToLambda(scope: Construct, id: string, props: AlbToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_alb_lambda import AlbToLambda, AlbToLambdaProps +from aws_cdk import ( + aws_certificatemanager as acm, + aws_lambda as _lambda, + aws_elasticloadbalancingv2 as alb, + Stack +) +from constructs import Construct + +# Obtain a pre-existing certificate from your account +certificate = acm.Certificate.from_certificate_arn( + self, + 'existing-cert', + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" +) + +# Note - all alb constructs turn on ELB logging by default, so require that an environment including account +# and region be provided when creating the stack +# +# MyStack(app, 'id', env=cdk.Environment(account='679431688440', region='us-east-1')) +AlbToLambda(self, 'new-construct', + lambda_function_props=_lambda.FunctionProps( + runtime=_lambda.Runtime.PYTHON_3_7, + code=_lambda.Code.from_asset('lambda'), + handler='index.handler', + ), + listener_props=alb.BaseApplicationListenerProps( + certificates=[certificate] + ), + public_api=True) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`AlbToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.elasticloadbalancingv2.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.alblambda.*; + +// Obtain a pre-existing certificate from your account +ListenerCertificate listenerCertificate = ListenerCertificate + .fromArn("arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012"); + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, "id", StackProps.builder() +// .env(Environment.builder() +// .account("123456789012") +// .region("us-east-1") +// .build()); +new AlbToLambda(this, "AlbToLambdaPattern", new AlbToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .listenerProps(new BaseApplicationListenerProps.Builder() + .certificates(List.of(listenerCertificate)) + .build()) + .publicApi(true) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md index e555d3768..237ba4334 100644 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/README.md @@ -26,26 +26,37 @@ ## Overview This AWS Solutions Construct implements an Amazon API Gateway REST API connected to Amazon DynamoDB table. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition in +Typescript: ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToDynamoDBProps, ApiGatewayToDynamoDB } from "@aws-solutions-constructs/aws-apigateway-dynamodb"; new ApiGatewayToDynamoDB(this, 'test-api-gateway-dynamodb-default', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_dynamodb import ApiGatewayToDynamoDB +from aws_cdk import Stack +from constructs import Construct -``` text -new ApiGatewayToDynamoDB(scope: Construct, id: string, props: ApiGatewayToDynamoDBProps); +ApiGatewayToDynamoDB(self, 'test-api-gateway-dynamodb-default') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.apigatewaydynamodb.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToDynamoDBProps`](#pattern-construct-props) +new ApiGatewayToDynamoDB(this, "test-api-gateway-dynamodb-default", new ApiGatewayToDynamoDBProps.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md index c28786e40..655f457ab 100755 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md @@ -30,29 +30,41 @@ This construct creates a scalable HTTPS proxy between API Gateway and AWS IoT. T This implementation enables write-only messages to be published on given MQTT topics, and also supports shadow updates of HTTPS devices to allowed things in the device registry. It does not involve Lambda functions for proxying messages, and instead relies on direct API Gateway to AWS IoT integration which supports both JSON messages as well as binary messages. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToIot } from '@aws-solutions-constructs/aws-apigateway-iot'; new ApiGatewayToIot(this, 'ApiGatewayToIotPattern', { iotEndpoint: 'a1234567890123-ats' }); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_iot import ApiGatewayToIot +from aws_cdk import Stack +from constructs import Construct -``` text -new ApiGatewayToIot(scope: Construct, id: string, props: ApiGatewayToIotProps); +ApiGatewayToIot(self, 'ApiGatewayToIotPattern', + iot_endpoint='a1234567890123-ats' +) ``` +Java +``` java +import software.constructs.Construct; -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToIotProps`](#pattern-construct-props) +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.apigatewayiot.*; +new ApiGatewayToIot(this, "ApiGatewayToIotPattern", new ApiGatewayToIotProps.Builder() + .iotEndpoint("a1234567890123-ats") + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-kinesisstreams/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-kinesisstreams/README.md index a3dd78c13..ecd0ca06c 100644 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-kinesisstreams/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-kinesisstreams/README.md @@ -22,26 +22,38 @@ This AWS Solutions Construct implements an Amazon API Gateway connected to an Amazon Kinesis Data Stream pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: -``` javascript +Typescript +``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToKinesisStreams, ApiGatewayToKinesisStreamsProps } from '@aws-solutions-constructs/aws-apigateway-kinesisstreams'; new ApiGatewayToKinesisStreams(this, 'test-apigw-kinesis', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_kinesisstreams import ApiGatewayToKinesisStreams +from aws_cdk import Stack +from constructs import Construct -``` text -new ApiGatewayToKinesisStreams(scope: Construct, id: string, props: ApiGatewayToKinesisStreamsProps); +ApiGatewayToKinesisStreams(self, 'test-apigw-kinesis') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.apigatewaykinesisstreams.*; + +new ApiGatewayToKinesisStreams(this, "test-apigw-kinesis", new ApiGatewayToKinesisStreamsProps.Builder() + .build()); +``` -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToKinesisStreamsProps`](#pattern-construct-props) ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md index de9a77233..0ff4e1c86 100644 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-lambda/README.md @@ -22,32 +22,61 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new ApiGatewayToLambda(this, 'ApiGatewayToLambdaPattern', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_lambda import ApiGatewayToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +ApiGatewayToLambda(self, 'ApiGatewayToLambdaPattern', + lambda_function_props=_lambda.FunctionProps( + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler', + code=_lambda.Code.from_asset('lambda') + ) + ) -``` text -new ApiGatewayToLambda(scope: Construct, id: string, props: ApiGatewayToLambdaProps); ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.apigatewaylambda.*; + +new ApiGatewayToLambda(this, "ApiGatewayToLambdaPattern", new ApiGatewayToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-sagemakerendpoint/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-sagemakerendpoint/README.md index fd86c4979..526e30937 100644 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-sagemakerendpoint/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sagemakerendpoint/README.md @@ -26,43 +26,93 @@ This AWS Solutions Construct implements an Amazon API Gateway connected to an Amazon SageMaker endpoint pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: -``` javascript +Typescript +``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToSageMakerEndpoint, ApiGatewayToSageMakerEndpointProps } from '@aws-solutions-constructs/aws-apigateway-sagemakerendpoint'; // Below is an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST request -const requestTemplate = -`{ +const requestTemplate = ` +{ "instances": [ -#set( $user_id = $input.params("user_id") ) -#set( $items = $input.params("items") ) -#foreach( $item in $items.split(",") ) - {"in0": [$user_id], "in1": [$item]}#if( $foreach.hasNext ),#end - $esc.newline -#end + # set( $user_id = $input.params("user_id") ) + # set( $items = $input.params("items") ) + # foreach( $item in $items.split(",") ) + # if( $foreach.hasNext ),#end + {"in0": [$user_id], "in1": [$item]} + $esc.newline + # end ] -}`; +}` // Replace 'my-endpoint' with your Sagemaker Inference Endpoint new ApiGatewayToSageMakerEndpoint(this, 'test-apigw-sagemakerendpoint', { - endpointName: 'my-endpoint', - resourcePath: '{user_id}', - requestMappingTemplate: requestTemplate + endpointName: 'my-endpoint', + resourcePath: '{user_id}', + requestMappingTemplate: requestTemplate }); ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_sagemakerendpoint import ApiGatewayToSageMakerEndpoint +from aws_cdk import Stack +from constructs import Construct -``` text -new ApiGatewayToSageMakerEndpoint(scope: Construct, id: string, props: ApiGatewayToSageMakerEndpointProps); +# Below is an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST request +request_template = """ +{ + "instances": [ + # set( $user_id = $input.params("user_id") ) + # set( $items = $input.params("items") ) + # foreach( $item in $items.split(",") ) + # if( $foreach.hasNext ),#end + {"in0": [$user_id], "in1": [$item]} + $esc.newline + # end + ] +}""" + +# Replace 'my-endpoint' with your Sagemaker Inference Endpoint +ApiGatewayToSageMakerEndpoint(self, 'test-apigw-sagemakerendpoint', + endpoint_name='my-endpoint', + resource_path='{user_id}', + request_mapping_template=request_template + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToSageMakerEndpointProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.apigatewaysagemakerendpoint.*; + +// Create an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST request +final String requestTemplate = "{" + + "\"instances\": [" + + "# set( $user_id = $input.params(\"user_id\") )" + + "# set( $items = $input.params(\"items\") )" + + "# foreach( $item in $items.split(\",\") )" + + "# if( $foreach.hasNext ),#end" + + "{\"in0\": [$user_id], \"in1\": [$item]}" + + " $esc.newline" + + "# end" + + "]" + + "}"; + +// Replace ""my-endpoint"" with your Sagemaker Inference Endpoint +new ApiGatewayToSageMakerEndpoint(this, "ApiGatewayToSageMakerEndpointPattern", + new ApiGatewayToSageMakerEndpointProps.Builder() + .endpointName("my-endpoint") + .resourcePath("{user_id}") + .requestMappingTemplate(requestTemplate) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md index c7c88eacb..5b6ddd7c2 100644 --- a/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/README.md @@ -22,26 +22,37 @@ This AWS Solutions Construct implements an Amazon API Gateway connected to an Amazon SQS queue pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { ApiGatewayToSqs, ApiGatewayToSqsProps } from "@aws-solutions-constructs/aws-apigateway-sqs"; new ApiGatewayToSqs(this, 'ApiGatewayToSqsPattern', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_apigateway_sqs import ApiGatewayToSqs +from aws_cdk import Stack +from constructs import Construct -``` text -new ApiGatewayToSqs(scope: Construct, id: string, props: ApiGatewayToSqsProps); +ApiGatewayToSqs(self, 'ApiGatewayToSqsPattern') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.apigatewaysqs.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`ApiGatewayToSqsProps`](#pattern-construct-props) +new ApiGatewayToSqs(this, "ApiGatewayToSqsPattern", new ApiGatewayToSqsProps.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md index ee9640d3e..08112642c 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway-lambda/README.md @@ -20,31 +20,62 @@ This AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway Lambda backed REST API. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CloudFrontToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cloudfront-apigateway-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new CloudFrontToApiGatewayToLambda(this, 'test-cloudfront-apigateway-lambda', { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - } + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + } }); ``` -## Initializer - -``` text -new CloudFrontToApiGatewayToLambda(scope: Construct, id: string, props: CloudFrontToApiGatewayToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_cloudfront_apigateway_lambda import CloudFrontToApiGatewayToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +CloudFrontToApiGatewayToLambda(self, 'test-cloudfront-apigateway-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.cloudfrontapigatewaylambda.*; + +new CloudFrontToApiGatewayToLambda(this, "test-cloudfront-apigateway-lambda", + new CloudFrontToApiGatewayToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`CloudFrontToApiGatewayToLambdaProps`](#pattern-construct-props) ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md index a16d7678c..c4b0dfb1b 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/README.md @@ -20,50 +20,100 @@ This AWS Solutions Construct implements an AWS CloudFront fronting an Amazon API Gateway REST API. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: -``` javascript -import * as api from '@aws-cdk/aws-apigateway'; -import * as lambda from "@aws-cdk/aws-lambda"; +Typescript +``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CloudFrontToApiGateway } from '@aws-solutions-constructs/aws-cloudfront-apigateway'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; +import * as api from 'aws-cdk-lib/aws-apigateway'; const lambdaProps: lambda.FunctionProps = { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' }; const lambdafunction = new lambda.Function(this, 'LambdaFunction', lambdaProps); const apiGatewayProps: api.LambdaRestApiProps = { - handler: lambdafunction, - endpointConfiguration: { - types: [api.EndpointType.REGIONAL] - }, - defaultMethodOptions: { - authorizationType: api.AuthorizationType.NONE - } + handler: lambdafunction, + endpointConfiguration: { + types: [api.EndpointType.REGIONAL] + }, + defaultMethodOptions: { + authorizationType: api.AuthorizationType.NONE + } }; const apiGateway = new api.LambdaRestApi(this, 'LambdaRestApi', apiGatewayProps); new CloudFrontToApiGateway(this, 'test-cloudfront-apigateway', { - existingApiGatewayObj: apiGateway + existingApiGatewayObj: apiGateway }); - ``` -## Initializer - -``` text -new CloudFrontToApiGateway(scope: Construct, id: string, props: CloudFrontToApiGatewayProps); +Python +``` python +from aws_solutions_constructs.aws_cloudfront_apigateway import CloudFrontToApiGateway +from aws_cdk import ( + aws_lambda as _lambda, + aws_apigateway as api, + Stack +) +from constructs import Construct + +lambda_function = _lambda.Function(self, 'LambdaFunction', + code=_lambda.Code.from_asset( + 'lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler') + +api_gateway = api.LambdaRestApi(self, 'LambdaRestApi', + handler=lambda_function, + endpoint_configuration=api.EndpointConfiguration( + types=[api.EndpointType.REGIONAL] + ), + default_method_options=api.MethodOptions( + authorization_type=api.AuthorizationType.NONE + )) + +CloudFrontToApiGateway(self, 'test-cloudfront-apigateway', + existing_api_gateway_obj=api_gateway + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`CloudFrontToApiGatewayProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.apigateway.*; +import software.amazon.awsconstructs.services.cloudfrontapigateway.*; + +final Function lambdaFunction = Function.Builder.create(this, "IndexHandler") + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build(); + +final LambdaRestApi apiGateway = LambdaRestApi.Builder.create(this, "myapi") + .handler(lambdaFunction) + .endpointConfiguration(new EndpointConfiguration.Builder() + .types(List.of(EndpointType.REGIONAL)) + .build()) + .build(); + +new CloudFrontToApiGateway(this, "test-cloudfront-apigateway", new CloudFrontToApiGatewayProps.Builder() + .existingApiGatewayObj(apiGateway) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/README.md index 6456ce764..70de0638d 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/README.md @@ -22,26 +22,37 @@ ## Overview This AWS Solutions Construct implements an Amazon CloudFront distribution to an AWS Elemental MediaStore container. -Here is a minimal deployable pattern definition in TypeScript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CloudFrontToMediaStore } from '@aws-solutions-constructs/aws-cloudfront-mediastore'; new CloudFrontToMediaStore(this, 'test-cloudfront-mediastore-default', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_cloudfront_mediastore import CloudFrontToMediaStore +from aws_cdk import Stack +from constructs import Construct -``` text -new CloudFrontToMediaStore(scope: Construct, id: string, props: CloudFrontToMediaStoreProps); +CloudFrontToMediaStore(self, 'test-cloudfront-mediastore-default') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.cloudfrontmediastore.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`CloudFrontToMediaStoreProps`](#pattern-construct-props) +new CloudFrontToMediaStore(this, "test-cloudfront-mediastore-default", new CloudFrontToMediaStoreProps.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md index df32a0149..d4c9bbbea 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/README.md @@ -20,26 +20,37 @@ This AWS Solutions Construct implements an AWS CloudFront fronting an AWS S3 Bucket. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3'; new CloudFrontToS3(this, 'test-cloudfront-s3', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_cloudfront_s3 import CloudFrontToS3 +from aws_cdk import Stack +from constructs import Construct -``` text -new CloudFrontToS3(scope: Construct, id: string, props: CloudFrontToS3Props); +CloudFrontToS3(self, 'test-cloudfront-s3') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.cloudfronts3.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`CloudFrontToS3Props`](#pattern-construct-props) +new CloudFrontToS3(this, "test-cloudfront-s3", new CloudFrontToS3Props.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md index e72d3931b..de4d94ef6 100644 --- a/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-cognito-apigateway-lambda/README.md @@ -24,33 +24,80 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CognitoToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cognito-apigateway-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new CognitoToApiGatewayToLambda(this, 'test-cognito-apigateway-lambda', { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - } + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + } }); ``` -If you are defining resources and methods on your API (e.g. proxy = false), then you must call addAuthorizers() after the API is fully defined to ensure every method is protected. Here is an example in Typescript: +Python +``` python +from aws_solutions_constructs.aws_cognito_apigateway_lambda import CognitoToApiGatewayToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +CognitoToApiGatewayToLambda(self, 'test-cognito-apigateway-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) +``` + +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.cognitoapigatewaylambda.*; + +new CognitoToApiGatewayToLambda(this, "test-cognito-apigateway-lambda", + new CognitoToApiGatewayToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` + +If you are defining resources and methods on your API (e.g. proxy = false), then you must call addAuthorizers() after the API is fully defined to ensure every method is protected. Here is an example: + +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CognitoToApiGatewayToLambda } from '@aws-solutions-constructs/aws-cognito-apigateway-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; const construct = new CognitoToApiGatewayToLambda(this, 'test-cognito-apigateway-lambda', { lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), + code: lambda.Code.fromAsset(`lambda`), runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler' }, apiGatewayProps: { - proxy: false + proxy: false } }); @@ -61,17 +108,73 @@ resource.addMethod('POST'); construct.addAuthorizers(); ``` -## Initializer - -``` text -new CognitoToApiGatewayToLambda(scope: Construct, id: string, props: CognitoToApiGatewayToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_cognito_apigateway_lambda import CognitoToApiGatewayToLambda +from aws_cdk import ( + aws_lambda as _lambda, + aws_apigateway as api, + Stack +) +from constructs import Construct +from typing import Any + +# Overriding LambdaRestApiProps with type Any +gateway_props = dict[Any, Any] + +construct = CognitoToApiGatewayToLambda(self, 'test-cognito-apigateway-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset( + 'lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + api_gateway_props=gateway_props( + proxy=False + ) + ) + +resource = construct.api_gateway.root.add_resource('foobar') +resource.add_method('POST') + +# Mandatory to call this method to Apply the Cognito Authorizers on all API methods +construct.add_authorizers() ``` -_Parameters_ +``` java +import software.constructs.Construct; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import software.amazon.awscdk.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.apigateway.IResource; +import software.amazon.awsconstructs.services.cognitoapigatewaylambda.*; + +// Overriding LambdaRestApiProps with type Any +Map> gatewayProps = new HashMap>(); +gatewayProps.put("proxy", Optional.of(false)); + +final CognitoToApiGatewayToLambda construct = new CognitoToApiGatewayToLambda(this, + "test-cognito-apigateway-lambda", + new CognitoToApiGatewayToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .apiGatewayProps(gatewayProps) + .build()); + +final IResource resource = construct.getApiGateway().getRoot().addResource("foobar"); +resource.addMethod("POST"); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`CognitoToApiGatewayToLambdaProps`](#pattern-construct-props) +// Mandatory to call this method to Apply the Cognito Authorizers on all API methods +construct.addAuthorizers(); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md index 751f159e9..574713cc8 100644 --- a/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana/README.md @@ -22,37 +22,74 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +// aws-dynamodb-stream-lambda-elasticsearch-kibana has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda-elasticsearch-kibana. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; +import * as lambda from '@aws-cdk/aws-lambda'; import { DynamoDBStreamToLambdaToElasticSearchAndKibana, DynamoDBStreamToLambdaToElasticSearchAndKibanaProps } from '@aws-solutions-constructs/aws-dynamodb-stream-lambda-elasticsearch-kibana'; -import { Aws } from "@aws-cdk/core"; -const props: DynamoDBStreamToLambdaToElasticSearchAndKibanaProps = { +const constructProps: DynamoDBStreamToLambdaToElasticSearchAndKibanaProps = { lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' }, domainName: 'test-domain', // TODO: Ensure the Cognito domain name is globally unique - cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID; + cognitoDomainName: 'globallyuniquedomain' + cdk.Aws.ACCOUNT_ID }; -new DynamoDBStreamToLambdaToElasticSearchAndKibana(this, 'test-dynamodb-stream-lambda-elasticsearch-kibana', props); +new DynamoDBStreamToLambdaToElasticSearchAndKibana(this, 'test', constructProps); ``` -## Initializer - -``` text -new DynamoDBStreamToLambdaToElasticSearchAndKibana(scope: Construct, id: string, props: DynamoDBStreamToLambdaToElasticSearchAndKibanaProps); +Python +``` python +# aws-dynamodb-stream-lambda-elasticsearch-kibana has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda-elasticsearch-kibana. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_dynamodb_stream_lambda_elasticsearch_kibana import DynamoDBStreamToLambdaToElasticSearchAndKibana, DynamoDBStreamToLambdaToElasticSearchAndKibanaProps +from aws_cdk import ( + aws_lambda as _lambda, + core +) + +DynamoDBStreamToLambdaToElasticSearchAndKibana( + self, 'test', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + domain_name='test-domain', + # TODO: Ensure the Cognito domain name is globally unique + cognito_domain_name='globallyuniquedomain' + core.Aws.ACCOUNT_ID) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`DynamoDBStreamToLambdaToElasticSearchAndKibanaProps`](#pattern-construct-props) +Java +``` java +// aws-dynamodb-stream-lambda-elasticsearch-kibana has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda-elasticsearch-kibana. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.dynamodbstreamlambdaelasticsearchkibana.*; + +new DynamoDBStreamToLambdaToElasticSearchAndKibana(this, "test", + new DynamoDBStreamToLambdaToElasticSearchAndKibanaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .domainName("test-domain") + .cognitoDomainName("globallyuniquedomain" + Aws.ACCOUNT_ID) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md index 8c78eaf78..a61f5c89f 100644 --- a/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/README.md @@ -21,32 +21,65 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { DynamoDBStreamToLambdaProps, DynamoDBStreamToLambda} from '@aws-solutions-constructs/aws-dynamodb-stream-lambda'; +// aws-dynamodb-stream-lambda has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; +import { DynamoDBStreamToLambda } from '@aws-solutions-constructs/aws-dynamodb-stream-lambda'; +import * as lambda from '@aws-cdk/aws-lambda'; new DynamoDBStreamToLambda(this, 'test-dynamodb-stream-lambda', { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, }); - ``` -## Initializer +Python +``` python +# aws-dynamodb-stream-lambda has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_dynamodb_stream_lambda import DynamoDBStreamToLambda +from aws_cdk import ( + aws_lambda as _lambda, + core, +) + +DynamoDBStreamToLambda(self, 'test-dynamodb-stream-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) -``` text -new DynamoDBStreamToLambda(scope: Construct, id: string, props: DynamoDBStreamToLambdaProps); ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`DynamoDBStreamToLambdaProps`](#pattern-construct-props) +Java +``` java +// aws-dynamodb-stream-lambda has been deprecated for CDK V2 in favor of aws-dynamodbstreams-lambda. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.dynamodbstreamlambda.*; + +new DynamoDBStreamToLambda(this, "test-dynamodbstreams-lambda", + new DynamoDBStreamToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda-elasticsearch-kibana/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda-elasticsearch-kibana/README.md index 82bc85882..538b96d2c 100644 --- a/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda-elasticsearch-kibana/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda-elasticsearch-kibana/README.md @@ -24,37 +24,73 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps, Aws } from 'aws-cdk-lib'; import { DynamoDBStreamsToLambdaToElasticSearchAndKibana, DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps } from '@aws-solutions-constructs/aws-dynamodbstreams-lambda-elasticsearch-kibana'; -import { Aws } from "@aws-cdk/core"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; -const props: DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps = { +const constructProps: DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps = { lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' }, domainName: 'test-domain', // TODO: Ensure the Cognito domain name is globally unique - cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID; + cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID }; -new DynamoDBStreamsToLambdaToElasticSearchAndKibana(this, 'test-dynamodbstreams-lambda-elasticsearch-kibana', props); +new DynamoDBStreamsToLambdaToElasticSearchAndKibana(this, 'test-dynamodbstreams-lambda-elasticsearch-kibana', constructProps); ``` -## Initializer - -``` text -new DynamoDBStreamsToLambdaToElasticSearchAndKibana(scope: Construct, id: string, props: DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps); +Python +``` Python +from aws_solutions_constructs.aws_dynamodbstreams_lambda_elasticsearch_kibana import DynamoDBStreamsToLambdaToElasticSearchAndKibana, DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps +from aws_cdk import ( + Stack, + aws_lambda as _lambda, + Aws, +) +from constructs import Construct + +DynamoDBStreamsToLambdaToElasticSearchAndKibana( + self, 'test-dynamodbstreams-lambda-elasticsearch-kibana', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + domain_name='test-domain', + # TODO: Ensure the Cognito domain name is globally unique + cognito_domain_name='globallyuniquedomain' + Aws.ACCOUNT_ID) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Aws; +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.dynamodbstreamslambdaelasticsearchkibana.*; + +new DynamoDBStreamsToLambdaToElasticSearchAndKibana(this, "test-dynamodb-stream-lambda-elasticsearch-kibana", + new DynamoDBStreamsToLambdaToElasticSearchAndKibanaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .domainName("test-domain") + .cognitoDomainName("globallyuniquedomain" + Aws.ACCOUNT_ID) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/README.md index 19ffad291..daf24e552 100644 --- a/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/README.md @@ -24,32 +24,61 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { DynamoDBStreamsToLambdaProps, DynamoDBStreamsToLambda} from '@aws-solutions-constructs/aws-dynamodbstreams-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new DynamoDBStreamsToLambda(this, 'test-dynamodbstreams-lambda', { lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), + code: lambda.Code.fromAsset(`lambda`), runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler' }, }); - ``` -## Initializer - -``` text -new DynamoDBStreamsToLambda(scope: Construct, id: string, props: DynamoDBStreamsToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_dynamodbstreams_lambda import DynamoDBStreamsToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +DynamoDBStreamsToLambda(self, 'test-dynamodbstreams-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`DynamoDBStreamsToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.dynamodbstreamslambda.*; + +new DynamoDBStreamsToLambda(this, "test-dynamodbstreams-lambda", + new DynamoDBStreamsToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3/README.md index 8fe08c6fa..ad6e38788 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3/README.md @@ -20,34 +20,58 @@ This AWS Solutions Construct implements an Amazon EventBridge 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 in Typescript: +Here is a minimal deployable pattern definition : +Typescript ``` javascript -import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; import { EventbridgeToKinesisFirehoseToS3, EventbridgeToKinesisFirehoseToS3Props } from '@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3'; +import * as events from 'aws-cdk-lib/aws-events'; const EventbridgeToKinesisFirehoseToS3Props: EventbridgeToKinesisFirehoseToS3Props = { eventRuleProps: { - schedule: events.Schedule.rate(cdk.Duration.minutes(5)) + schedule: events.Schedule.rate(Duration.minutes(5)) } }; new EventbridgeToKinesisFirehoseToS3(this, 'test-eventbridge-firehose-s3', EventbridgeToKinesisFirehoseToS3Props); - ``` -## Initializer - -``` text -new EventbridgeToKinesisFirehoseToS3(scope: Construct, id: string, props: EventbridgeToKinesisFirehoseToS3Props); +Python +``` python +from aws_solutions_constructs.aws_eventbridge_kinesis_firehose_s3 import EventbridgeToKinesisFirehoseToS3, EventbridgeToKinesisFirehoseToS3Props +from aws_cdk import ( + aws_events as events, + Duration, + Stack +) +from constructs import Construct + +EventbridgeToKinesisFirehoseToS3(self, 'test-eventbridge-firehose-s3', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + Duration.minutes(5)) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToKinesisFirehoseToS3Props`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awsconstructs.services.eventbridgekinesisfirehoses3.*; + +new EventbridgeToKinesisFirehoseToS3(this, "test-eventbridge-firehose-s3", + new EventbridgeToKinesisFirehoseToS3Props.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisstreams/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisstreams/README.md index 01510ac13..625b4e54e 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisstreams/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisstreams/README.md @@ -24,33 +24,57 @@ This AWS Solutions Construct implements an Amazon EventBridge rule to send data to an Amazon Kinesis Data Stream -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import * as cdk from '@aws-cdk/core'; -import {EventbridgeToKinesisStreams, EventbridgeToKinesisStreamsProps} from "@aws-solutions-constructs/aws-eventbridge-kinesisstreams"; - -const props: EventbridgeToKinesisStreamsProps = { - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)), - } +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import { EventbridgeToKinesisStreams, EventbridgeToKinesisStreamsProps } from "@aws-solutions-constructs/aws-eventbridge-kinesisstreams"; +import * as events from 'aws-cdk-lib/aws-events'; + +const constructProps: EventbridgeToKinesisStreamsProps = { + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)), + } }; -new EventbridgeToKinesisStreams(this, 'test-eventbridge-kinesis-streams', props); +new EventbridgeToKinesisStreams(this, 'test-eventbridge-kinesis-streams', constructProps); ``` -## Initializer - -``` text -new EventbridgeToKinesisStreams(scope: Construct, id: string, props: EventbridgeToKinesisStreamsProps); +Python +``` Python +from aws_solutions_constructs.aws_eventbridge_kinesis_streams import EventbridgeToKinesisStreams, EventbridgeToKinesisStreamsProps +from aws_cdk import ( + aws_events as events, + Duration, + Stack +) +from constructs import Construct + +EventbridgeToKinesisStreams(self, 'test-eventbridge-kinesis-streams', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate(Duration.minutes(5)), + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToKinesisStreamsProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awsconstructs.services.eventbridgekinesisstreams.*; + +new EventbridgeToKinesisStreams(this, "test-eventbridge-kinesis-streams", + new EventbridgeToKinesisStreamsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/README.md index a642d2499..e30afa303 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/README.md @@ -20,36 +20,77 @@ This AWS Solutions Construct implements an AWS EventBridge rule and an AWS Lambda function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { EventbridgeToLambdaProps, EventbridgeToLambda } from '@aws-solutions-constructs/aws-eventbridge-lambda'; - -const props: EventbridgeToLambdaProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)) - } +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import { EventbridgeToLambdaProps, EventbridgeToLambda } from '@aws-solutions-constructs/aws-eventbridge-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; +import * as events from 'aws-cdk-lib/aws-events'; + +const constructProps: EventbridgeToLambdaProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } }; -new EventbridgeToLambda(this, 'test-eventbridge-lambda', props); +new EventbridgeToLambda(this, 'test-eventbridge-lambda', constructProps); ``` -## Initializer - -``` text -new EventbridgeToLambda(scope: Construct, id: string, props: EventbridgeToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_eventbridge_lambda import EventbridgeToLambda, EventbridgeToLambdaProps +from aws_cdk import ( + aws_lambda as _lambda, + aws_events as events, + Duration, + Stack +) +from constructs import Construct + +EventbridgeToLambda(self, 'test-eventbridge-lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + Duration.minutes(5)) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.eventbridgelambda.*; + +new EventbridgeToLambda(this, "test-eventbridge-lambda", + new EventbridgeToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/README.md index 4c7f72cb7..94fe8880c 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/README.md @@ -20,44 +20,92 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS SNS Topic. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { Duration } from '@aws-cdk/core'; -import * as events from '@aws-cdk/aws-events'; -import * as iam from '@aws-cdk/aws-iam'; +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import * as events from 'aws-cdk-lib/aws-events'; +import * as iam from 'aws-cdk-lib/aws-iam'; import { EventbridgeToSnsProps, EventbridgeToSns } from "@aws-solutions-constructs/aws-eventbridge-sns"; -const props: EventbridgeToSnsProps = { - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)), - } +const constructProps: EventbridgeToSnsProps = { + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } }; -const constructStack = new EventbridgeToSns(this, 'test-construct', props); +const constructStack = new EventbridgeToSns(this, 'test-construct', constructProps); // Grant yourself permissions to use the Customer Managed KMS Key const policyStatement = new iam.PolicyStatement({ - actions: ["kms:Encrypt", "kms:Decrypt"], - effect: iam.Effect.ALLOW, - principals: [ new iam.AccountRootPrincipal() ], - resources: [ "*" ] + actions: ["kms:Encrypt", "kms:Decrypt"], + effect: iam.Effect.ALLOW, + principals: [new iam.AccountRootPrincipal()], + resources: ["*"] }); constructStack.encryptionKey?.addToResourcePolicy(policyStatement); ``` -## Initializer - -``` text -new EventbridgeToSns(scope: Construct, id: string, props: EventbridgeToSnsProps); +Python +``` Python +from aws_solutions_constructs.aws_eventbridge_sns import EventbridgeToSns, EventbridgeToSnsProps +from aws_cdk import ( + aws_events as events, + aws_iam as iam, + Duration, + Stack +) +from constructs import Construct + +construct_stack = EventbridgeToSns(self, 'test-construct', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + Duration.minutes(5)) + )) + +# Grant yourself permissions to use the Customer Managed KMS Key +policy_statement = iam.PolicyStatement( + actions=["kms:Encrypt", "kms:Decrypt"], + effect=iam.Effect.ALLOW, + principals=[iam.AccountRootPrincipal()], + resources=["*"] +) + +construct_stack.encryption_key.add_to_resource_policy(policy_statement) ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.iam.*; +import software.amazon.awsconstructs.services.eventbridgesns.*; + +final EventbridgeToSns constructStack = new EventbridgeToSns(this, "test-construct", + new EventbridgeToSnsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToSnsProps`](#pattern-construct-props) +// Grant yourself permissions to use the Customer Managed KMS Key +final PolicyStatement policyStatement = PolicyStatement.Builder.create() + .actions(List.of("kms:Encrypt", "kms:Decrypt")) + .effect(Effect.ALLOW) + .principals(List.of(new AccountRootPrincipal())) + .resources(List.of("*")) + .build(); + +constructStack.getEncryptionKey().addToResourcePolicy(policyStatement); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/README.md index 9d4fa70fb..3c6830f4c 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/README.md @@ -20,44 +20,92 @@ This AWS Solutions Construct implements an Amazon EventBridge rule and an AWS SQS Queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { Duration } from '@aws-cdk/core'; -import * as events from '@aws-cdk/aws-events'; -import * as iam from '@aws-cdk/aws-iam'; +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import * as events from 'aws-cdk-lib/aws-events'; +import * as iam from 'aws-cdk-lib/aws-iam'; import { EventbridgeToSqsProps, EventbridgeToSqs } from "@aws-solutions-constructs/aws-eventbridge-sqs"; -const props: EventbridgeToSqsProps = { +const constructProps: EventbridgeToSqsProps = { eventRuleProps: { schedule: events.Schedule.rate(Duration.minutes(5)) } }; -const constructStack = new EventbridgeToSqs(this, 'test-construct', props); +const constructStack = new EventbridgeToSqs(this, 'test-construct', constructProps); // Grant yourself permissions to use the Customer Managed KMS Key const policyStatement = new iam.PolicyStatement({ actions: ["kms:Encrypt", "kms:Decrypt"], effect: iam.Effect.ALLOW, - principals: [ new iam.AccountRootPrincipal() ], - resources: [ "*" ] + principals: [new iam.AccountRootPrincipal()], + resources: ["*"] }); constructStack.encryptionKey?.addToResourcePolicy(policyStatement); ``` -## Initializer - -``` text -new EventbridgeToSqs(scope: Construct, id: string, props: EventbridgeToSqsProps); +Python +``` Python +from aws_solutions_constructs.aws_eventbridge_sqs import EventbridgeToSqsProps, EventbridgeToSqs +from aws_cdk import ( + aws_events as events, + aws_iam as iam, + Duration, + Stack +) +from constructs import Construct + +construct_stack = EventbridgeToSqs(self, 'test-construct', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + Duration.minutes(5)) + )) + +# Grant yourself permissions to use the Customer Managed KMS Key +policy_statement = iam.PolicyStatement( + actions=["kms:Encrypt", "kms:Decrypt"], + effect=iam.Effect.ALLOW, + principals=[iam.AccountRootPrincipal()], + resources=["*"] +) + +construct_stack.encryption_key.add_to_resource_policy(policy_statement) ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.iam.*; +import software.amazon.awsconstructs.services.eventbridgesqs.*; + +final EventbridgeToSqs constructStack = new EventbridgeToSqs(this, "test-construct", + new EventbridgeToSqsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToSqsProps`](#pattern-construct-props) +// Grant yourself permissions to use the Customer Managed KMS Key +final PolicyStatement policyStatement = PolicyStatement.Builder.create() + .actions(List.of("kms:Encrypt", "kms:Decrypt")) + .effect(Effect.ALLOW) + .principals(List.of(new AccountRootPrincipal())) + .resources(List.of("*")) + .build(); + +constructStack.getEncryptionKey().addToResourcePolicy(policyStatement); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-eventbridge-stepfunctions/README.md b/source/patterns/@aws-solutions-constructs/aws-eventbridge-stepfunctions/README.md index cac4b2368..70d177844 100644 --- a/source/patterns/@aws-solutions-constructs/aws-eventbridge-stepfunctions/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-eventbridge-stepfunctions/README.md @@ -20,36 +20,77 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS Step Functions State Machine -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { EventbridgeToStepfunctions, EventbridgeToStepfunctionsProps } from '@aws-solutions-constructs/aws-eventbridge-stepfunctions'; +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import { EventbridgeToStepfunctions, EventbridgeToStepfunctionsProps } from '@aws-solutions-constructs/aws-eventbridge-stepfunctions'; +import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions'; +import * as events from 'aws-cdk-lib/aws-events'; const startState = new stepfunctions.Pass(this, 'StartState'); -const props: EventbridgeToStepfunctionsProps = { - stateMachineProps: { - definition: startState - }, - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)) - } +const constructProps: EventbridgeToStepfunctionsProps = { + stateMachineProps: { + definition: startState + }, + eventRuleProps: { + schedule: events.Schedule.rate(Duration.minutes(5)) + } }; -new EventbridgeToStepfunctions(stack, 'test-eventbridge-stepfunctions-stack', props); +new EventbridgeToStepfunctions(this, 'test-eventbridge-stepfunctions-stack', constructProps); ``` -## Initializer - -``` text -new EventbridgeToStepfunctions(scope: Construct, id: string, props: EventbridgeToStepfunctionsProps); +Python +``` python +from aws_solutions_constructs.aws_eventbridge_stepfunctions import EventbridgeToStepfunctions, EventbridgeToStepfunctionsProps +from aws_cdk import ( + aws_stepfunctions as stepfunctions, + aws_events as events, + Duration, + Stack +) +from constructs import Construct + +startState = stepfunctions.Pass(self, 'StartState') + +EventbridgeToStepfunctions(self, 'test-eventbridge-stepfunctions-stack', + state_machine_props=stepfunctions.StateMachineProps( + definition=startState + ), + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + Duration.minutes(5)) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventbridgeToStepfunctionsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.eventbridgestepfunctions.*; + +final Pass startState = new Pass(this, "StartState"); + +new EventbridgeToStepfunctions(this, + "test-eventbridge-stepfunctions-stack", + new EventbridgeToStepfunctionsProps.Builder() + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3/README.md index 5c1c36d2b..ae83d3809 100644 --- a/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3/README.md @@ -22,33 +22,60 @@ This AWS Solutions Construct implements an Amazon CloudWatch Events 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 in Typescript: +Here is a minimal deployable pattern definition: -``` javascript +Typescript +``` typescript +// aws-events-rule-kinesisfirehose-s3 has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisfirehose-s3. +// This sample uses the CDK V1 syntax import * as cdk from '@aws-cdk/core'; -import { EventsRuleToKinesisFirehoseToS3, EventsRuleToKinesisFirehoseToS3Props } from '@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3'; +import * as events from '@aws-cdk/aws-events'; +import { EventsRuleToKinesisFirehoseToS3Props, EventsRuleToKinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-events-rule-kinesisfirehose-s3'; const eventsRuleToKinesisFirehoseToS3Props: EventsRuleToKinesisFirehoseToS3Props = { - eventRuleProps: { + eventRuleProps: { schedule: events.Schedule.rate(cdk.Duration.minutes(5)) - } + } }; new EventsRuleToKinesisFirehoseToS3(this, 'test-events-rule-firehose-s3', eventsRuleToKinesisFirehoseToS3Props); +``` +Python +``` python +# aws-events-rule-kinesisfirehose-s3 has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisfirehose-s3. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_kinesis_firehose_s3 import EventsRuleToKinesisFirehoseToS3, EventsRuleToKinesisFirehoseToS3Props +from aws_cdk import ( + aws_events as events, + core +) + +EventsRuleToKinesisFirehoseToS3(self, 'test_events_rule_firehose_s3', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + core.Duration.minutes(5)) + )) ``` -## Initializer +Java +``` java +// aws-events-rule-kinesisfirehose-s3 has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisfirehose-s3. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; +import software.amazon.awscdk.core.*; -``` text -new EventsRuleToKinesisFirehoseToS3(scope: Construct, id: string, props: EventsRuleToKinesisFirehoseToS3Props); -``` +import software.amazon.awscdk.services.events.*; +import software.amazon.awsconstructs.services.eventsrulekinesisfirehoses3.*; -_Parameters_ -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventsRuleToKinesisFirehoseToS3Props`](#pattern-construct-props) +new EventsRuleToKinesisFirehoseToS3(this, "test-events-rule-firehose-s3", + new EventsRuleToKinesisFirehoseToS3Props.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisstreams/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisstreams/README.md index 3d771ed94..7f6309c74 100644 --- a/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisstreams/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-kinesisstreams/README.md @@ -22,32 +22,59 @@ This AWS Solutions Construct implements an Amazon CloudWatch Events rule to send data to an Amazon Kinesis data stream. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +// aws-events-rule-kinesisstreams has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisstreams. +// This sample uses the CDK V1 syntax import * as cdk from '@aws-cdk/core'; -import {EventsRuleToKinesisStreams, EventsRuleToKinesisStreamsProps} from "@aws-solutions-constructs/aws-events-rule-kinesisstreams"; +import * as events from '@aws-cdk/aws-events'; +import { EventsRuleToKinesisStreams, EventsRuleToKinesisStreamsProps } from "@aws-solutions-constructs/aws-events-rule-kinesisstreams"; -const props: EventsRuleToKinesisStreamsProps = { - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)), - } +const constructProps: EventsRuleToKinesisStreamsProps = { + eventRuleProps: { + schedule: events.Schedule.rate(cdk.Duration.minutes(5)), + } }; -new EventsRuleToKinesisStreams(this, 'test-events-rule-kinesis-streams', props); +new EventsRuleToKinesisStreams(this, 'test-events-rule-kinesis-streams', constructProps); ``` -## Initializer - -``` text -new EventsRuleToKinesisStreams(scope: Construct, id: string, props: EventsRuleToKinesisStreamsProps); +Python +``` python +# aws-events-rule-kinesisstreams has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisstreams. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_kinesis_streams import EventsRuleToKinesisStreams, EventsRuleToKinesisStreamsProps +from aws_cdk import ( + aws_events as events, + core +) + +EventsRuleToKinesisStreams(self, 'test_events_rule_kinesis_streams', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + core.Duration.minutes(5)), + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventsRuleToKinesisStreamsProps`](#pattern-construct-props) +Java +``` java +// aws-events-rule-kinesisstreams has been deprecated for CDK V2 in favor of aws-eventbridge-kinesisstreams. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.events.*; +import software.amazon.awsconstructs.services.eventsrulekinesisstreams.*; + +new EventsRuleToKinesisStreams(this, "test-events-rule-kinesis-streams", + new EventsRuleToKinesisStreamsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md index e63157f03..3c0087832 100644 --- a/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-lambda/README.md @@ -22,36 +22,77 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS Lambda function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript +// aws-events-rule-lambda has been deprecated for CDK V2 in favor of aws-eventbridge-lambda. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; +import * as lambda from '@aws-cdk/aws-lambda'; +import * as events from '@aws-cdk/aws-events'; import { EventsRuleToLambdaProps, EventsRuleToLambda } from '@aws-solutions-constructs/aws-events-rule-lambda'; -const props: EventsRuleToLambdaProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)) - } +const constructProps: EventsRuleToLambdaProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, + eventRuleProps: { + schedule: events.Schedule.rate(cdk.Duration.minutes(5)) + } }; -new EventsRuleToLambda(this, 'test-events-rule-lambda', props); +new EventsRuleToLambda(this, 'test-events-rule-lambda', constructProps); ``` -## Initializer - -``` text -new EventsRuleToLambda(scope: Construct, id: string, props: EventsRuleToLambdaProps); +Python +``` python +# aws-events-rule-lambda has been deprecated for CDK V2 in favor of aws-eventbridge-lambda. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_lambda import EventsRuleToLambdaProps, EventsRuleToLambda +from aws_cdk import ( + aws_lambda as _lambda, + aws_events as events, + core +) + +EventsRuleToLambda(self, 'test_events_rule_lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate(core.Duration.minutes(5)) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventsRuleToLambdaProps`](#pattern-construct-props) +Java +``` java +// aws-events-rule-lambda has been deprecated for CDK V2 in favor of aws-eventbridge-lambda. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.eventsrulelambda.*; + +new EventsRuleToLambda(this, "test-events-rule-lambda", + new EventsRuleToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-sns/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-sns/README.md index c45bf8914..81e0a0d32 100644 --- a/source/patterns/@aws-solutions-constructs/aws-events-rule-sns/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-sns/README.md @@ -21,44 +21,93 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS SNS Topic. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { Duration } from '@aws-cdk/core'; +// aws-events-rule-sns has been deprecated for CDK V2 in favor of aws-eventbridge-sns. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; import * as events from '@aws-cdk/aws-events'; import * as iam from '@aws-cdk/aws-iam'; import { EventsRuleToSnsProps, EventsRuleToSns } from "@aws-solutions-constructs/aws-events-rule-sns"; -const props: EventsRuleToSnsProps = { - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)), - } +const constructProps: EventsRuleToSnsProps = { + eventRuleProps: { + schedule: events.Schedule.rate(cdk.Duration.minutes(5)), + } }; -const constructStack = new EventsRuleToSns(this, 'test-construct', props); +const constructStack = new EventsRuleToSns(this, 'test', constructProps); // Grant yourself permissions to use the Customer Managed KMS Key const policyStatement = new iam.PolicyStatement({ - actions: ["kms:Encrypt", "kms:Decrypt"], - effect: iam.Effect.ALLOW, - principals: [ new iam.AccountRootPrincipal() ], - resources: [ "*" ] + actions: ["kms:Encrypt", "kms:Decrypt"], + effect: iam.Effect.ALLOW, + principals: [new iam.AccountRootPrincipal()], + resources: ["*"] }); constructStack.encryptionKey?.addToResourcePolicy(policyStatement); ``` -## Initializer - -``` text -new EventsRuleToSns(scope: Construct, id: string, props: EventsRuleToSnsProps); +Python +``` python +# aws-events-rule-sns has been deprecated for CDK V2 in favor of aws-eventbridge-sns. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_sns import EventsRuleToSns, EventsRuleToSnsProps +from aws_cdk import ( + aws_events as events, + aws_iam as iam, + core +) + +construct_stack = EventsRuleToSns(self, 'test', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + core.Duration.minutes(5)) + )) + +# Grant yourself permissions to use the Customer Managed KMS Key +policy_statement = iam.PolicyStatement( + actions=["kms:Encrypt", "kms:Decrypt"], + effect=iam.Effect.ALLOW, + principals=[iam.AccountRootPrincipal()], + resources=["*"] +) + +construct_stack.encryption_key.add_to_resource_policy(policy_statement) ``` -_Parameters_ +Java +``` java +// aws-events-rule-sns has been deprecated for CDK V2 in favor of aws-eventbridge-sns. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.iam.*; +import software.amazon.awsconstructs.services.eventsrulesns.*; + +final EventsRuleToSns constructStack = new EventsRuleToSns(this, "test", + new EventsRuleToSnsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventsRuleToSnsProps`](#pattern-construct-props) +// Grant yourself permissions to use the Customer Managed KMS Key +final PolicyStatement policyStatement = PolicyStatement.Builder.create() + .actions(List.of("kms:Encrypt", "kms:Decrypt")) + .effect(Effect.ALLOW) + .principals(List.of(new AccountRootPrincipal())) + .resources(List.of("*")) + .build(); + +constructStack.getEncryptionKey().addToResourcePolicy(policyStatement); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/README.md index 1f14a5332..6ea791e66 100644 --- a/source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/README.md @@ -22,45 +22,93 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS SQS Queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { Duration } from '@aws-cdk/core'; +// aws-events-rule-sqs has been deprecated for CDK V2 in favor of aws-eventbridge-sqs. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; import * as events from '@aws-cdk/aws-events'; import * as iam from '@aws-cdk/aws-iam'; import { EventsRuleToSqsProps, EventsRuleToSqs } from "@aws-solutions-constructs/aws-events-rule-sqs"; -const props: EventsRuleToSqsProps = { - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)) - } +const constructProps: EventsRuleToSqsProps = { + eventRuleProps: { + schedule: events.Schedule.rate(cdk.Duration.minutes(5)) + } }; -const constructStack = new EventsRuleToSqs(this, 'test-construct', props); +const constructStack = new EventsRuleToSqs(this, 'test', constructProps); // Grant yourself permissions to use the Customer Managed KMS Key const policyStatement = new iam.PolicyStatement({ - actions: ["kms:Encrypt", "kms:Decrypt"], - effect: iam.Effect.ALLOW, - principals: [ new iam.AccountRootPrincipal() ], - resources: [ "*" ] + actions: ["kms:Encrypt", "kms:Decrypt"], + effect: iam.Effect.ALLOW, + principals: [new iam.AccountRootPrincipal()], + resources: ["*"] }); constructStack.encryptionKey?.addToResourcePolicy(policyStatement); ``` -## Initializer - -``` text -new EventsRuleToSqs(scope: Construct, id: string, props: EventsRuleToSqsProps); +Python +``` python +# aws-events-rule-sqs has been deprecated for CDK V2 in favor of aws-eventbridge-sqs. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_sqs import EventsRuleToSqs +from aws_cdk import ( + aws_events as events, + aws_iam as iam, + core +) + +construct_stack = EventsRuleToSqs(self, 'test', + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + core.Duration.minutes(5)) + )) + +# Grant yourself permissions to use the Customer Managed KMS Key +policy_statement = iam.PolicyStatement( + actions=["kms:Encrypt", "kms:Decrypt"], + effect=iam.Effect.ALLOW, + principals=[iam.AccountRootPrincipal()], + resources=["*"] +) + +construct_stack.encryption_key.add_to_resource_policy(policy_statement) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`EventsRuleToSqsProps`](#pattern-construct-props) +Java +``` java +// aws-events-rule-sqs has been deprecated for CDK V2 in favor of aws-eventbridge-sqs. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.iam.*; +import software.amazon.awsconstructs.services.eventsrulesqs.*; + +final EventsRuleToSqs constructStack = new EventsRuleToSqs(this, "test-construct", + new EventsRuleToSqsProps.Builder() + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +// Grant yourself permissions to use the Customer Managed KMS Key +final PolicyStatement policyStatement = PolicyStatement.Builder.create() + .actions(List.of("kms:Encrypt", "kms:Decrypt")) + .effect(Effect.ALLOW) + .principals(List.of(new AccountRootPrincipal())) + .resources(List.of("*")) + .build(); + +constructStack.getEncryptionKey().addToResourcePolicy(policyStatement); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | 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 index c4122fef9..9436187c9 100644 --- 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 @@ -22,36 +22,79 @@ This AWS Solutions Construct implements an AWS Events rule and an AWS Step function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } from '@aws-solutions-constructs/aws-events-rule-step-function'; +// aws-events-rule-step-function has been deprecated for CDK V2 in favor of aws-eventbridge-stepfunctions. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; +import * as events from '@aws-cdk/aws-events'; +import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; +import { EventsRuleToStepFunction, EventsRuleToStepFunctionProps } from '@aws-solutions-constructs/aws-events-rule-step-function'; const startState = new stepfunctions.Pass(this, 'StartState'); -const props: EventsRuleToStepFunctionProps = { - stateMachineProps: { - definition: startState - }, - eventRuleProps: { - schedule: events.Schedule.rate(Duration.minutes(5)) - } +const constructProps: EventsRuleToStepFunctionProps = { + stateMachineProps: { + definition: startState + }, + eventRuleProps: { + schedule: events.Schedule.rate(cdk.Duration.minutes(5)) + } }; -new EventsRuleToStepFunction(stack, 'test-events-rule-step-function-stack', props); +new EventsRuleToStepFunction(this, 'test-events-rules-step-function-stack', constructProps); ``` -## Initializer +Python +``` Python +# aws-events-rule-step-function has been deprecated for CDK V2 in favor of aws-eventbridge-stepfunctions. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_events_rule_step_function import EventsRuleToStepFunction, EventsRuleToStepFunctionProps +from aws_cdk import ( + aws_stepfunctions as stepfunctions, + aws_events as events, + core +) + +startState = stepfunctions.Pass(self, 'StartState') + +EventsRuleToStepFunction(self, 'test', + state_machine_props=stepfunctions.StateMachineProps( + definition=startState + ), + event_rule_props=events.RuleProps( + schedule=events.Schedule.rate( + core.Duration.minutes(5)) + )) -``` 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) +Java +``` java +// aws-events-rule-step-function has been deprecated for CDK V2 in favor of aws-eventbridge-stepfunctions. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.events.*; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.eventsrulestepfunction.*; + +final Pass startState = new Pass(this, "StartState"); + +new EventsRuleToStepFunction(this, + "test-eventbridge-stepfunctions-stack", + new EventsRuleToStepFunctionProps.Builder() + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .eventRuleProps(new RuleProps.Builder() + .schedule(Schedule.rate(Duration.minutes(5))) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-fargate-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-fargate-s3/README.md index 158a01948..be6592805 100644 --- a/source/patterns/@aws-solutions-constructs/aws-fargate-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-fargate-s3/README.md @@ -24,19 +24,48 @@ This AWS Solutions Construct implements an AWS Fargate service that can write/read to an Amazon S3 Bucket -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { FargateToS3, FargateToS3Props } from '@aws-solutions-constructs/aws-fargate-s3'; -const props: FargateToS3Props = { +const constructProps: FargateToS3Props = { publicApi: true, - ecrRepositoryArn: "arn of a repo in ECR in your account", -}); + ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo", +}; -new FargateToS3(stack, 'test-construct', props); +new FargateToS3(this, 'test-construct', constructProps); ``` +Python +``` python +from aws_solutions_constructs.aws_fargate_s3 import FargateToS3, FargateToS3Props +from aws_cdk import ( + Stack +) +from constructs import Construct + +FargateToS3(self, 'test_construct', + public_api=True, + ecr_repository_arn="arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") +``` + +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.fargates3.*; + +new FargateToS3(this, "test_construct", new FargateToS3Props.Builder() + .publicApi(true) + .ecrRepositoryArn("arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-fargate-sns/README.md b/source/patterns/@aws-solutions-constructs/aws-fargate-sns/README.md index a388aa729..cd0b685c1 100644 --- a/source/patterns/@aws-solutions-constructs/aws-fargate-sns/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-fargate-sns/README.md @@ -24,37 +24,48 @@ This AWS Solutions Construct implements an AWS Fargate service that can write to an Amazon SNS topic -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript - import { FargateToSns, FargateToSnsProps } from '@aws-solutions-constructs/aws-fargate-sns'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { FargateToSns, FargateToSnsProps } from '@aws-solutions-constructs/aws-fargate-sns'; - // Obtain a pre-existing certificate from your account - const certificate = acm.Certificate.fromCertificateArn( - scope, - 'existing-cert', - "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" - ); - - const props: FargateToSnsProps = { +const constructProps: FargateToSnsProps = { publicApi: true, - ecrRepositoryArn: "arn of a repo in ECR in your account", - }); + ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo" +}; - new FargateToSns(stack, 'test-construct', props); +new FargateToSns(this, 'test-construct', constructProps); ``` -## Initializer - -``` text -new FargateToSns(scope: Construct, id: string, props: FargateToSnsProps); +Python +``` python +from aws_solutions_constructs.aws_fargate_sns import FargateToSns, FargateToSnsProps +from aws_cdk import ( + Stack +) +from constructs import Construct + +FargateToSns(self, 'test_construct', + public_api=True, + ecr_repository_arn="arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`FargateToSnsProps`](#pattern-construct-props) +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.fargatesns.*; + +new FargateToSns(this, "test_construct", new FargateToSnsProps.Builder() + .publicApi(true) + .ecrRepositoryArn("arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-fargate-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-fargate-sqs/README.md index bac1870ac..e2e56737b 100644 --- a/source/patterns/@aws-solutions-constructs/aws-fargate-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-fargate-sqs/README.md @@ -28,14 +28,43 @@ Here is a minimal deployable pattern definition: Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { FargateToSqs, FargateToSqsProps } from '@aws-solutions-constructs/aws-fargate-sqs'; -const props: FargateToSqsProps = { +const constructProps: FargateToSqsProps = { publicApi: true, - ecrRepositoryArn: "arn of a repo in ECR in your account", -}); + ecrRepositoryArn: "arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo" +}; -new FargateToSqs(stack, 'test-construct', props); +new FargateToSqs(this, 'test-construct', constructProps); +``` + +Python +``` python +from aws_solutions_constructs.aws_fargate_sqs import FargateToSqs, FargateToSqsProps +from aws_cdk import ( + Stack +) +from constructs import Construct + +FargateToSqs(self, 'test_construct', + public_api=True, + ecr_repository_arn="arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") +``` + +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.fargatesqs.*; + +new FargateToSqs(this, "test_construct", new FargateToSqsProps.Builder() + .publicApi(true) + .ecrRepositoryArn("arn:aws:ecr:us-east-1:123456789012:repository/your-ecr-repo") + .build()); ``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md index 4f4c3187b..90726a44e 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisfirehose-s3/README.md @@ -24,12 +24,15 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { IotToKinesisFirehoseToS3Props, IotToKinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-iot-kinesisfirehose-s3'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToKinesisFirehoseToS3Props, IotToKinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-iot-kinesisfirehose-s3'; -const props: IotToKinesisFirehoseToS3Props = { +const constructProps: IotToKinesisFirehoseToS3Props = { iotTopicRuleProps: { topicRulePayload: { ruleDisabled: false, @@ -40,21 +43,52 @@ const props: IotToKinesisFirehoseToS3Props = { } }; -new IotToKinesisFirehoseToS3(this, 'test-iot-firehose-s3', props); - +new IotToKinesisFirehoseToS3(this, 'test-iot-firehose-s3', constructProps); ``` -## Initializer +Python +```python +from aws_solutions_constructs.aws_iot_kinesisfirehose_s3 import IotToKinesisFirehoseToS3Props, IotToKinesisFirehoseToS3 +from aws_cdk import ( + aws_iot as iot, + Stack +) +from constructs import Construct + +IotToKinesisFirehoseToS3(self, 'test_iot_firehose_s3', + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Persistent storage of connected vehicle telematics data", + sql="SELECT * FROM 'connectedcar/telemetry/#'", + actions=[] + ) + )) -``` text -new IotToKinesisFirehoseToS3(scope: Construct, id: string, props: IotToKinesisFirehoseToS3Props); ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToKinesisFirehoseToS3Props`](#pattern-construct-props) +Java +```java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iotkinesisfirehoses3.*; + +new IotToKinesisFirehoseToS3(this, "test-iot-firehose-s3", new IotToKinesisFirehoseToS3Props.Builder() + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Persistent storage of connected vehicle telematics data") + .sql("SELECT * FROM 'connectedcar/telemetry/#'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-kinesisstreams/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisstreams/README.md index a9b19b582..d907934bd 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-kinesisstreams/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-kinesisstreams/README.md @@ -24,38 +24,70 @@ This AWS Solutions Construct implements an AWS IoT MQTT topic rule to send data to an Amazon Kinesis Data Stream. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -const { IotToKinesisStreamsProps, - IotToKinesisStreams } from '@aws-solutions-constructs/aws-iot-kinesisstreams'; - -const props: IotToKinesisStreamsProps = { - iotTopicRuleProps: { - topicRulePayload: { - ruleDisabled: false, - description: "Sends data to kinesis data stream", - sql: "SELECT * FROM 'solutions/construct'", - actions: [] - } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToKinesisStreamsProps, IotToKinesisStreams } from '@aws-solutions-constructs/aws-iot-kinesisstreams'; + +const constructProps: IotToKinesisStreamsProps = { + iotTopicRuleProps: { + topicRulePayload: { + ruleDisabled: false, + description: "Sends data to kinesis data stream", + sql: "SELECT * FROM 'solutions/construct'", + actions: [] } + } }; -new IotToKinesisStreams(this, 'test-iot-kinesisstream', props); - +new IotToKinesisStreams(this, 'test-iot-kinesisstreams', constructProps); ``` -## Initializer - -``` text -new IotToKinesisStreams(scope: Construct, id: string, props: IotToKinesisStreamsProps); +Python +``` python +from aws_solutions_constructs.aws_iot_kinesisstreams import IotToKinesisStreamsProps, IotToKinesisStreams +from aws_cdk import ( + aws_iot as iot, + Stack +) +from constructs import Construct + +IotToKinesisStreams(self, 'test-iot-kinesisstreams', + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Sends data to kinesis data stream", + sql="SELECT * FROM 'solutions/construct'", + actions=[] + ) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToKinesisStreamsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iotkinesisstreams.*; + +new IotToKinesisStreams(this, "test-iot-kinesisstreams", new IotToKinesisStreamsProps.Builder() + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Sends data to kinesis data stream") + .sql("SELECT * FROM 'solutions/construct'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md index 3b36e462b..e6312b6c7 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/README.md @@ -24,42 +24,89 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { IotToLambdaToDynamoDBProps, IotToLambdaToDynamoDB } from '@aws-solutions-constructs/aws-iot-lambda-dynamodb'; - -const props: IotToLambdaToDynamoDBProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, - iotTopicRuleProps: { - topicRulePayload: { - ruleDisabled: false, - description: "Processing of DTC messages from the AWS Connected Vehicle Solution.", - sql: "SELECT * FROM 'connectedcar/dtc/#'", - actions: [] - } - } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToLambdaToDynamoDBProps, IotToLambdaToDynamoDB } from '@aws-solutions-constructs/aws-iot-lambda-dynamodb'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +const constructProps: IotToLambdaToDynamoDBProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, + iotTopicRuleProps: { + topicRulePayload: { + ruleDisabled: false, + description: "Processing of DTC messages from the AWS Connected Vehicle Solution.", + sql: "SELECT * FROM 'connectedcar/dtc/#'", + actions: [] + } + } }; -new IotToLambdaToDynamoDB(this, 'test-iot-lambda-dynamodb-stack', props); - +new IotToLambdaToDynamoDB(this, 'test-iot-lambda-dynamodb-stack', constructProps); ``` -## Initializer - -``` text -new IotToLambdaToDynamoDB(scope: Construct, id: string, props: IotToLambdaToDynamoDBProps); +Python +``` python +from aws_solutions_constructs.aws_iot_lambda_dynamodb import IotToLambdaToDynamoDB +from aws_cdk import ( + aws_iot as iot, + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +IotToLambdaToDynamoDB(self, 'test-iot-lambda-dynamodb-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Processing of DTC messages from the AWS Connected Vehicle Solution.", + sql="SELECT * FROM 'connectedcar/dtc/#'", + actions=[] + ) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToLambdaToDynamoDBProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iotlambdadynamodb.*; + +new IotToLambdaToDynamoDB(this, "test-iot-lambda-dynamodb-stack", new IotToLambdaToDynamoDBProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Processing of DTC messages from the AWS Connected Vehicle Solution.") + .sql("SELECT * FROM 'connectedcar/dtc/#'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md index efb20accf..60eb219c0 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-lambda/README.md @@ -24,42 +24,89 @@ This AWS Solutions Construct implements an AWS IoT MQTT topic rule and an AWS Lambda function pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { IotToLambdaProps, IotToLambda } from '@aws-solutions-constructs/aws-iot-lambda'; - -const props: IotToLambdaProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, - iotTopicRuleProps: { - topicRulePayload: { - ruleDisabled: false, - description: "Processing of DTC messages from the AWS Connected Vehicle Solution.", - sql: "SELECT * FROM 'connectedcar/dtc/#'", - actions: [] - } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToLambdaProps, IotToLambda } from '@aws-solutions-constructs/aws-iot-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +const constructProps: IotToLambdaProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, + iotTopicRuleProps: { + topicRulePayload: { + ruleDisabled: false, + description: "Processing of DTC messages from the AWS Connected Vehicle Solution.", + sql: "SELECT * FROM 'connectedcar/dtc/#'", + actions: [] } + } }; -new IotToLambda(this, 'test-iot-lambda-integration', props); +new IotToLambda(this, 'test-iot-lambda-integration', constructProps); ``` -## Initializer - -``` text -new IotToLambda(scope: Construct, id: string, props: IotToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_iot_lambda import IotToLambdaProps, IotToLambda +from aws_cdk import ( + aws_iot as iot, + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +IotToLambda(self, 'test_iot_lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Sends data to kinesis data stream", + sql="SELECT * FROM 'solutions/construct'", + actions=[] + ) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToLambdaProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iotlambda.*; + +new IotToLambda(this, "test-iot-lambda-integration", new IotToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Processing of DTC messages from the AWS Connected Vehicle Solution.") + .sql("SELECT * FROM 'connectedcar/dtc/#'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-s3/README.md index 6db3afc11..db0733821 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-s3/README.md @@ -24,37 +24,71 @@ This AWS Solutions Construct implements an AWS IoT MQTT topic rule and an Amazon S3 Bucket pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -const { IotToS3Props, IotToS3 } from '@aws-solutions-constructs/aws-iot-s3'; - -const props: IotToS3Props = { - iotTopicRuleProps: { - topicRulePayload: { - ruleDisabled: false, - description: "Testing the IotToS3 Pattern", - sql: "SELECT * FROM 'solutions/constructs'", - actions: [] - } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToS3Props, IotToS3 } from '@aws-solutions-constructs/aws-iot-s3'; + +const constructProps: IotToS3Props = { + iotTopicRuleProps: { + topicRulePayload: { + ruleDisabled: false, + description: "Testing the IotToS3 Pattern", + sql: "SELECT * FROM 'solutions/constructs'", + actions: [] } + } }; -new IotToS3(this, 'test-iot-s3-integration', props); +new IotToS3(this, 'test-iot-s3-integration', constructProps); ``` -## Initializer - -``` text -new IotToS3(scope: Construct, id: string, props: IotToS3Props); +Python +``` python +from aws_solutions_constructs.aws_iot_s3 import IotToS3Props, IotToS3 +from aws_cdk import ( + aws_iot as iot, + Stack +) +from constructs import Construct + + +IotToS3(self, 'test_iot_s3', + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Testing the IotToS3 Pattern", + sql="SELECT * FROM 'solutions/constructs'", + actions=[] + ) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToS3Props`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iots3.*; + +new IotToS3(this, "test_iot_s3", new IotToS3Props.Builder() + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Testing the IotToS3 Pattern") + .sql("SELECT * FROM 'solutions/constructs'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-iot-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-iot-sqs/README.md index 5ebccb509..78157133a 100644 --- a/source/patterns/@aws-solutions-constructs/aws-iot-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-iot-sqs/README.md @@ -24,36 +24,70 @@ This AWS Solutions Construct implements an AWS IoT MQTT topic rule and an AWS SQS Queue pattern. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -const { IotToSqsProps, IotToSqs } from '@aws-solutions-constructs/aws-iot-sqs'; - -const props: IotToSqsProps = { - iotTopicRuleProps: { - topicRulePayload: { - ruleDisabled: false, - description: "Testing the IotToSqs Pattern", - sql: "SELECT * FROM 'iot/sqs/#'", - actions: [] - } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { IotToSqsProps, IotToSqs } from '@aws-solutions-constructs/aws-iot-sqs'; + +const constructProps: IotToSqsProps = { + iotTopicRuleProps: { + topicRulePayload: { + ruleDisabled: false, + description: "Testing the IotToSqs Pattern", + sql: "SELECT * FROM 'iot/sqs/#'", + actions: [] } + } }; -new IotToSqs(this, 'test-iot-sqs-integration', props); +new IotToSqs(this, 'test-iot-sqs-integration', constructProps); ``` -## Initializer - -``` text -new IotToSqs(scope: Construct, id: string, props: IotToSqsProps); +Python +``` python +from aws_solutions_constructs.aws_iot_sqs import IotToSqs +from aws_cdk import ( + aws_iot as iot, + Stack +) +from constructs import Construct + +IotToSqs(self, 'test_iot_sqs', + iot_topic_rule_props=iot.CfnTopicRuleProps( + topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty( + rule_disabled=False, + description="Testing the IotToSqs Pattern", + sql="SELECT * FROM 'iot/sqs/#'", + actions=[] + ) + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`IotToSqsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.iot.*; +import software.amazon.awscdk.services.iot.CfnTopicRule.TopicRulePayloadProperty; +import software.amazon.awsconstructs.services.iotsqs.*; + +new IotToSqs(this, "test_iot_sqs", new IotToSqsProps.Builder() + .iotTopicRuleProps(new CfnTopicRuleProps.Builder() + .topicRulePayload(new TopicRulePayloadProperty.Builder() + .ruleDisabled(false) + .description("Testing the IotToSqs Pattern") + .sql("SELECT * FROM 'iot/sqs/#'") + .actions(List.of()) + .build()) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md index 2b2d6140f..6008416ba 100644 --- a/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics/README.md @@ -24,55 +24,134 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { KinesisFirehoseToAnalyticsAndS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { KinesisFirehoseToAnalyticsAndS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3-and-kinesisanalytics'; new KinesisFirehoseToAnalyticsAndS3(this, 'FirehoseToS3AndAnalyticsPattern', { - kinesisAnalyticsProps: { - inputs: [{ - inputSchema: { - recordColumns: [{ - name: 'ticker_symbol', - sqlType: 'VARCHAR(4)', - mapping: '$.ticker_symbol' - }, { - name: 'sector', - sqlType: 'VARCHAR(16)', - mapping: '$.sector' - }, { - name: 'change', - sqlType: 'REAL', - mapping: '$.change' - }, { - name: 'price', - sqlType: 'REAL', - mapping: '$.price' - }], - recordFormat: { - recordFormatType: 'JSON' - }, - recordEncoding: 'UTF-8' - }, - namePrefix: 'SOURCE_SQL_STREAM' - }] - } + kinesisAnalyticsProps: { + inputs: [{ + inputSchema: { + recordColumns: [{ + name: 'ticker_symbol', + sqlType: 'VARCHAR(4)', + mapping: '$.ticker_symbol' + }, { + name: 'sector', + sqlType: 'VARCHAR(16)', + mapping: '$.sector' + }, { + name: 'change', + sqlType: 'REAL', + mapping: '$.change' + }, { + name: 'price', + sqlType: 'REAL', + mapping: '$.price' + }], + recordFormat: { + recordFormatType: 'JSON' + }, + recordEncoding: 'UTF-8' + }, + namePrefix: 'SOURCE_SQL_STREAM' + }] + } }); - ``` -## Initializer - -``` text -new KinesisFirehoseToAnalyticsAndS3(scope: Construct, id: string, props: KinesisFirehoseToAnalyticsAndS3Props); +Python +```python +from aws_solutions_constructs.aws_kinesis_firehose_s3_kinesis_analytics import KinesisFirehoseToAnalyticsAndS3 +from aws_cdk import ( + aws_kinesisanalytics as kinesisanalytics, + Stack +) +from constructs import Construct + +KinesisFirehoseToAnalyticsAndS3(self, 'FirehoseToS3AndAnalyticsPattern', + kinesis_analytics_props=kinesisanalytics.CfnApplicationProps( + inputs=[kinesisanalytics.CfnApplication.InputProperty( + input_schema=kinesisanalytics.CfnApplication.InputSchemaProperty( + record_columns=[kinesisanalytics.CfnApplication.RecordColumnProperty( + name='ticker_symbol', + sql_type='VARCHAR(4)', + mapping='$.ticker_symbol' + ), kinesisanalytics.CfnApplication.RecordColumnProperty( + name='sector', + sql_type='VARCHAR(16)', + mapping='$.sector' + ), kinesisanalytics.CfnApplication.RecordColumnProperty( + name='change', + sql_type='REAL', + mapping='$.change' + ), kinesisanalytics.CfnApplication.RecordColumnProperty( + name='price', + sql_type='REAL', + mapping='$.price' + )], + record_format=kinesisanalytics.CfnApplication.RecordFormatProperty( + record_format_type='JSON' + ), + record_encoding='UTF-8' + ), + name_prefix='SOURCE_SQL_STREAM' + )] + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`KinesisFirehoseToAnalyticsAndS3Props`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; +import java.util.List; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.kinesisanalytics.*; +import software.amazon.awscdk.services.kinesisanalytics.CfnApplication.*; +import software.amazon.awsconstructs.services.kinesisfirehoses3kinesisanalytics.*; + +new KinesisFirehoseToAnalyticsAndS3(this, "FirehoseToS3AndAnalyticsPattern", + new KinesisFirehoseToAnalyticsAndS3Props.Builder() + .kinesisAnalyticsProps(new CfnApplicationProps.Builder() + .inputs(List.of(new InputProperty.Builder() + .inputSchema(new InputSchemaProperty.Builder() + .recordColumns(List.of( + new RecordColumnProperty.Builder() + .name("ticker_symbol") + .sqlType("VARCHAR(4)") + .mapping("$.ticker_symbol") + .build(), + new RecordColumnProperty.Builder() + .name("sector") + .sqlType("VARCHAR(16)") + .mapping("$.sector") + .build(), + new RecordColumnProperty.Builder() + .name("change") + .sqlType("REAL") + .mapping("$.change") + .build(), + new RecordColumnProperty.Builder() + .name("price") + .sqlType("REAL") + .mapping("$.price") + .build())) + .recordFormat(new RecordFormatProperty.Builder() + .recordFormatType("JSON") + .build()) + .recordEncoding("UTF-8") + .build()) + .namePrefix("SOURCE_SQL_STREAM") + .build())) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md index a823ee740..9916fc726 100644 --- a/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md @@ -20,26 +20,37 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3'; new KinesisFirehoseToS3(this, 'test-firehose-s3', {}); - ``` -## Initializer +Python +```python +from aws_solutions_constructs.aws_kinesis_firehose_s3 import KinesisFirehoseToS3 +from aws_cdk import Stack +from constructs import Construct -``` text -new KinesisFirehoseToS3(scope: Construct, id: string, props: KinesisFirehoseToS3Props); +KinesisFirehoseToS3(self, 'test_firehose_s3') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.kinesisfirehoses3.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`KinesisFirehoseToS3Props`](#pattern-construct-props) +new KinesisFirehoseToS3(this, "test_firehose_s3", new KinesisFirehoseToS3Props.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/README.md index cbff5c585..4459f0a84 100644 --- a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/README.md @@ -27,8 +27,9 @@ This AWS Solutions Construct deploys a Kinesis Stream and configures a AWS Glue Job to perform custom ETL transformation with the appropriate resources/properties for interaction and security. It also creates an S3 bucket where the python script for the AWS Glue Job can be uploaded. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ```javascript import * as glue from "@aws-cdk/aws-glue"; import * as s3assets from "@aws-cdk/aws-s3-assets"; @@ -71,18 +72,6 @@ const customEtlJob = new KinesisstreamsToGluejob(this, "CustomETL", { }); ``` -## Initializer - -```text -new KinesisstreamsToGluejob(scope: Construct, id: string, props: KinesisstreamsToGluejobProps); -``` - -_Parameters_ - -- scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -- id `string` -- props [`KinesisstreamsToGluejobProps`](#pattern-construct-props) - ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-kinesisfirehose-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-kinesisfirehose-s3/README.md index 14ad702ae..d7ca78e01 100644 --- a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-kinesisfirehose-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-kinesisfirehose-s3/README.md @@ -20,26 +20,37 @@ This AWS Solutions Construct implements an Amazon Kinesis Data Stream (KDS) connected to Amazon Kinesis Data Firehose (KDF) delivery stream connected to an Amazon S3 bucket. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { KinesisStreamsToKinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisstreams-kinesisfirehose-s3'; new KinesisStreamsToKinesisFirehoseToS3(this, 'test-stream-firehose-s3', {}); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_kinesis_streams_kinesis_firehose_s3 import KinesisStreamsToKinesisFirehoseToS3 +from aws_cdk import Stack +from constructs import Construct -``` text -new KinesisStreamsToKinesisFirehoseToS3(scope: Construct, id: string, props: KinesisStreamsToKinesisFirehoseToS3Props); +KinesisStreamsToKinesisFirehoseToS3(self, 'test_stream_firehose_s3') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.kinesisstreamskinesisfirehoses3.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`KinesisStreamsToKinesisFirehoseToS3Props`](#pattern-construct-props) +new KinesisStreamsToKinesisFirehoseToS3(this, "test_stream_firehose_s3", new KinesisStreamsToKinesisFirehoseToS3Props.Builder() + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md index ae6407a81..431477afa 100644 --- a/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-kinesisstreams-lambda/README.md @@ -20,36 +20,77 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { KinesisStreamsToLambda } from '@aws-solutions-constructs/aws-kinesisstreams-lambda'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { KinesisStreamsToLambda } from '@aws-solutions-constructs/aws-kinesisstreams-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new KinesisStreamsToLambda(this, 'KinesisToLambdaPattern', { - kinesisEventSourceProps: { - startingPosition: lambda.StartingPosition.TRIM_HORIZON, - batchSize: 1 - }, - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + kinesisEventSourceProps: { + startingPosition: lambda.StartingPosition.TRIM_HORIZON, + batchSize: 1 + }, + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` -## Initializer +Python +``` python +from aws_solutions_constructs.aws_kinesis_streams_lambda import KinesisStreamsToLambda +from aws_cdk import ( + aws_lambda as _lambda, + aws_lambda_event_sources as sources, + aws_kinesis as kinesis, + Stack +) +from constructs import Construct + +KinesisStreamsToLambda(self, 'KinesisToLambdaPattern', + kinesis_event_source_props=sources.KinesisEventSourceProps( + starting_position=_lambda.StartingPosition.TRIM_HORIZON, + batch_size=1 + ), + lambda_function_props=_lambda.FunctionProps( + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler', + code=_lambda.Code.from_asset( + 'lambda') + ) + ) -``` text -new KinesisStreamsToLambda(scope: Construct, id: string, props: KinesisStreamsToLambdaProps); ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`KinesisStreamsToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.eventsources.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.kinesisstreamslambda.*; + +new KinesisStreamsToLambda(this, "KinesisToLambdaPattern", new KinesisStreamsToLambdaProps.Builder() + .kinesisEventSourceProps(new KinesisEventSourceProps.Builder() + .startingPosition(StartingPosition.TRIM_HORIZON) + .batchSize(1) + .build()) + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md index 382141c42..64292598a 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/README.md @@ -20,34 +20,62 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { LambdaToDynamoDBProps, LambdaToDynamoDB } from '@aws-solutions-constructs/aws-lambda-dynamodb'; - -const props: LambdaToDynamoDBProps = { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { LambdaToDynamoDBProps, LambdaToDynamoDB } from '@aws-solutions-constructs/aws-lambda-dynamodb'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +const constructProps: LambdaToDynamoDBProps = { + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, }; -new LambdaToDynamoDB(this, 'test-lambda-dynamodb-stack', props); - +new LambdaToDynamoDB(this, 'test-lambda-dynamodb-stack', constructProps); ``` -## Initializer - -``` text -new LambdaToDynamoDB(scope: Construct, id: string, props: LambdaToDynamoDBProps); +Python +```python +from aws_solutions_constructs.aws_lambda_dynamodb import LambdaToDynamoDBProps, LambdaToDynamoDB +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToDynamoDB(self, 'test_lambda_dynamodb_stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset( + 'lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + )) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToDynamoDBProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdadynamodb.*; + +new LambdaToDynamoDB(this, "test_lambda_dynamodb_stack", new LambdaToDynamoDBProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md index 330af28c2..464891b08 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-elasticsearch-kibana/README.md @@ -24,39 +24,76 @@ 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 in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps, Aws } from 'aws-cdk-lib'; import { LambdaToElasticSearchAndKibana } from '@aws-solutions-constructs/aws-lambda-elasticsearch-kibana'; -import { Aws } from "@aws-cdk/core"; +import * as lambda from "aws-cdk-lib/aws-lambda"; const lambdaProps: lambda.FunctionProps = { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' }; -new LambdaToElasticSearchAndKibana(this, 'test-lambda-elasticsearch-kibana', { - lambdaFunctionProps: lambdaProps, - domainName: 'test-domain', - // TODO: Ensure the Cognito domain name is globally unique - cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID; +new LambdaToElasticSearchAndKibana(this, 'sample', { + lambdaFunctionProps: lambdaProps, + domainName: 'testdomain', + // TODO: Ensure the Cognito domain name is globally unique + cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID }); - ``` -## Initializer - -``` text -new LambdaToElasticSearchAndKibana(scope: Construct, id: string, props: LambdaToElasticSearchAndKibanaProps); +Python +```python +from aws_solutions_constructs.aws_lambda_elasticsearch_kibana import LambdaToElasticSearchAndKibana +from aws_cdk import ( + aws_lambda as _lambda, + Aws, + Stack +) +from constructs import Construct + +lambda_props = _lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' +) + +LambdaToElasticSearchAndKibana(self, 'sample', + lambda_function_props=lambda_props, + domain_name='testdomain', + # TODO: Ensure the Cognito domain name is globally unique + cognito_domain_name='globallyuniquedomain' + Aws.ACCOUNT_ID + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToElasticSearchAndKibanaProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Aws; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdaelasticsearchkibana.*; + +new LambdaToElasticSearchAndKibana(this, "sample", + new LambdaToElasticSearchAndKibanaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .domainName("testdomain") + // TODO: Ensure the Cognito domain name is globally unique + .cognitoDomainName("globallyuniquedomain" + Aws.ACCOUNT_ID) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/README.md index acb7d7433..2c4cf9200 100755 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/README.md @@ -24,33 +24,60 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon EventBridge. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps, Aws } from 'aws-cdk-lib'; import { LambdaToEventbridge, LambdaToEventbridgeProps } from "@aws-solutions-constructs/aws-lambda-eventbridge"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new LambdaToEventbridge(this, 'LambdaToEventbridgePattern', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` -## Initializer - -``` text -new LambdaToEventbridge(scope: Construct, id: string, props: LambdaToEventbridgeProps); +Python +```python +from aws_solutions_constructs.aws_lambda_eventbridge import LambdaToEventbridge +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToEventbridge(self, 'LambdaToEventbridgePattern', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToEventbridgeProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdaeventbridge.*; + +new LambdaToEventbridge(this, "LambdaToEventbridgePattern", new LambdaToEventbridgeProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md index d3a83bea7..aceff41ff 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-s3/README.md @@ -20,32 +20,60 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon S3 bucket. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition : +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { LambdaToS3 } from '@aws-solutions-constructs/aws-lambda-s3'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new LambdaToS3(this, 'LambdaToS3Pattern', { lambdaFunctionProps: { runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) + code: lambda.Code.fromAsset(`lambda`) } }); - ``` -## Initializer - -``` text -new LambdaToS3(scope: Construct, id: string, props: LambdaToS3Props); +Python +```python +from aws_solutions_constructs.aws_lambda_s3 import LambdaToS3 +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToS3(self, 'LambdaToS3Pattern', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToS3Props`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdas3.*; + +new LambdaToS3(this, "LambdaToS3Pattern", new LambdaToS3Props.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/README.md index 99e7b5311..14a65b251 100755 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/README.md @@ -28,26 +28,25 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon Sagemaker Endpoint. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ```typescript -import { Duration } from '@aws-cdk/core'; -import * as lambda from '@aws-cdk/aws-lambda'; -import { - LambdaToSagemakerEndpoint, - LambdaToSagemakerEndpointProps, -} from '@aws-solutions-constructs/aws-lambda-sagemakerendpoint'; +import { Construct } from 'constructs'; +import { Stack, StackProps, Duration } from 'aws-cdk-lib'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; +import { LambdaToSagemakerEndpoint, LambdaToSagemakerEndpointProps } from '@aws-solutions-constructs/aws-lambda-sagemakerendpoint'; const constructProps: LambdaToSagemakerEndpointProps = { modelProps: { primaryContainer: { image: '.dkr.ecr..amazonaws.com/linear-learner:latest', - modelDataUrl: 's3:////model.tar.gz', + modelDataUrl: "s3:////model.tar.gz", }, }, lambdaFunctionProps: { runtime: lambda.Runtime.PYTHON_3_8, - code: lambda.Code.fromAsset(`${__dirname}/lambda`), + code: lambda.Code.fromAsset(`lambda`), handler: 'index.handler', timeout: Duration.minutes(5), memorySize: 128, @@ -57,17 +56,65 @@ const constructProps: LambdaToSagemakerEndpointProps = { new LambdaToSagemakerEndpoint(this, 'LambdaToSagemakerEndpointPattern', constructProps); ``` -## Initializer - -```text -new LambdaToSagemakerEndpoint(scope: Construct, id: string, props: LambdaToSagemakerEndpointProps); +Python +```python +from constructs import Construct +from aws_solutions_constructs.aws_lambda_sagemakerendpoint import LambdaToSagemakerEndpoint, LambdaToSagemakerEndpointProps +from aws_cdk import ( + aws_lambda as _lambda, + aws_sagemaker as sagemaker, + Duration, + Stack +) +from constructs import Construct + +LambdaToSagemakerEndpoint( + self, 'LambdaToSagemakerEndpointPattern', + model_props=sagemaker.CfnModelProps( + primary_container=sagemaker.CfnModel.ContainerDefinitionProperty( + image='.dkr.ecr..amazonaws.com/linear-learner:latest', + model_data_url='s3:////model.tar.gz', + ), + execution_role_arn="executionRoleArn" + ), + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler', + timeout=Duration.minutes(5), + memory_size=128 + )) ``` -_Parameters_ - -- scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -- id `string` -- props [`LambdaToSagemakerEndpointProps`](#pattern-construct-props) +Java +```java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.Duration; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.sagemaker.*; +import software.amazon.awsconstructs.services.lambdasagemakerendpoint.*; + +new LambdaToSagemakerEndpoint(this, "LambdaToSagemakerEndpointPattern", + new LambdaToSagemakerEndpointProps.Builder() + .modelProps(new CfnModelProps.Builder() + .primaryContainer(new CfnModel.ContainerDefinitionProperty.Builder() + .image(".dkr.ecr..amazonaws.com/linear_learner:latest") + .modelDataUrl("s3:////model.tar.gz") + .build()) + .executionRoleArn("executionRoleArn") + .build()) + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .timeout(Duration.minutes(5)) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/README.md index fb50924f8..07244b563 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/README.md @@ -24,36 +24,64 @@ This AWS Solutions Construct implements the AWS Lambda function and AWS Secrets Manager secret with the least privileged permissions. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { LambdaToSecretsmanagerProps, LambdaToSecretsmanager } from '@aws-solutions-constructs/aws-lambda-secretsmanager'; - -const props: LambdaToSecretsmanagerProps = { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - // This assumes a handler function in lib/lambda/index.js - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - handler: 'index.handler' - }, +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { LambdaToSecretsmanagerProps, LambdaToSecretsmanager } from '@aws-solutions-constructs/aws-lambda-secretsmanager'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +const constructProps: LambdaToSecretsmanagerProps = { + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + code: lambda.Code.fromAsset(`lambda`), + handler: 'index.handler' + }, }; -new LambdaToSecretsmanager(this, 'test-lambda-secretsmanager-stack', props); - +new LambdaToSecretsmanager(this, 'test-lambda-secretsmanager-stack', constructProps); ``` -## Initializer - -``` text -new LambdaToSecretsmanager(scope: Construct, id: string, props: LambdaToSecretsmanagerProps); +Python +``` python +from aws_solutions_constructs.aws_lambda_secretsmanager import LambdaToSecretsmanagerProps, LambdaToSecretsmanager +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + + +LambdaToSecretsmanager( + self, 'test-lambda-secretsmanager-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToSecretsmanagerProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdasecretsmanager.*; + +new LambdaToSecretsmanager(this, "test-lambda-secretsmanager-stack", new LambdaToSecretsmanagerProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md index f82fe30a9..a6d11356e 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sns/README.md @@ -20,32 +20,61 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon SNS topic. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { LambdaToSns, LambdaToSnsProps } from "@aws-solutions-constructs/aws-lambda-sns"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new LambdaToSns(this, 'test-lambda-sns', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` -## Initializer - -``` text -new LambdaToSns(scope: Construct, id: string, props: LambdaToSnsProps); +Python +``` python +from aws_solutions_constructs.aws_lambda_sns import LambdaToSns +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToSns( + self, 'test-lambda-sns-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToSnsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdasns.*; + +new LambdaToSns(this, "test-lambda-sns-stack", new LambdaToSnsProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/README.md index cf76b3389..ea019928d 100755 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/README.md @@ -24,38 +24,76 @@ This AWS Solutions Construct implements (1) an AWS Lambda function that is configured to send messages to a queue; (2) an Amazon SQS queue; and (3) an AWS Lambda function configured to consume messages from the queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { LambdaToSqsToLambda, LambdaToSqsToLambdaProps } from "@aws-solutions-constructs/aws-lambda-sqs-lambda"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new LambdaToSqsToLambda(this, 'LambdaToSqsToLambdaPattern', { producerLambdaFunctionProps: { runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda/producer-function`) + code: lambda.Code.fromAsset(`producer-lambda`) }, consumerLambdaFunctionProps: { runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda/consumer-function`) + code: lambda.Code.fromAsset(`consumer-lambda`) } }); - ``` -## Initializer - -``` text -new LambdaToSqsToLambda(scope: Construct, id: string, props: LambdaToSqsToLambdaProps); +Python +```python +from aws_solutions_constructs.aws_lambda_sqs_lambda import LambdaToSqsToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToSqsToLambda( + self, 'LambdaToSqsToLambdaPattern', + producer_lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('producer_lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + consumer_lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('consumer_lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToSqsToLambdaProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdasqslambda.*; + +new LambdaToSqsToLambda(this, "LambdaToSqsToLambdaPattern", new LambdaToSqsToLambdaProps.Builder() + .producerLambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("producer-lambda")) + .handler("index.handler") + .build()) + .consumerLambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("consumer-lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-sqs/README.md index 34ad9d80d..25836880a 100755 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-sqs/README.md @@ -20,32 +20,61 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon SQS queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { LambdaToSqs, LambdaToSqsProps } from "@aws-solutions-constructs/aws-lambda-sqs"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new LambdaToSqs(this, 'LambdaToSqsPattern', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` -## Initializer - -``` text -new LambdaToSqs(scope: Construct, id: string, props: LambdaToSqsProps); +Python +``` python +from aws_solutions_constructs.aws_lambda_sqs import LambdaToSqs +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +LambdaToSqs( + self, 'test-lambda-sqs-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToSqsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.lambdasqs.*; + +new LambdaToSqs(this, "test-lambda-sqs-stack", new LambdaToSqsProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-ssmstringparameter/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-ssmstringparameter/README.md index 4cb84dcb6..5d97fa9b7 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-ssmstringparameter/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-ssmstringparameter/README.md @@ -24,36 +24,72 @@ This AWS Solutions Construct implements the AWS Lambda function and AWS Systems Manager Parameter Store String parameter with the least privileged permissions. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` javascript -const { LambdaToSsmstringparameterProps, LambdaToSsmstringparameter } from '@aws-solutions-constructs/aws-lambda-ssmstringparameter'; - -const props: LambdaToSsmstringparameterProps = { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - // This assumes a handler function in lib/lambda/index.js - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - handler: 'index.handler' - }, - stringParameterProps: { stringValue: "test-string-value" } +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { LambdaToSsmstringparameterProps, LambdaToSsmstringparameter } from '@aws-solutions-constructs/aws-lambda-ssmstringparameter'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; + +const constructProps: LambdaToSsmstringparameterProps = { + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + code: lambda.Code.fromAsset(`lambda`), + handler: 'index.handler' + }, + stringParameterProps: { stringValue: "test-string-value" } }; -new LambdaToSsmstringparameter(this, 'test-lambda-ssmstringparameter-stack', props); - +new LambdaToSsmstringparameter(this, 'test-lambda-ssmstringparameter-stack', constructProps); ``` -## Initializer - -``` text -new LambdaToSsmstringparameter(scope: Construct, id: string, props: LambdaToSsmstringparameterProps); +Python +```python +from aws_solutions_constructs.aws_lambda_ssmstringparameter import LambdaToSsmstringparameter +from aws_cdk import ( + aws_lambda as _lambda, + aws_ssm as ssm, + Stack +) +from constructs import Construct + +LambdaToSsmstringparameter( + self, 'test-lambda-ssmstringparameter-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + string_parameter_props=ssm.StringParameterProps( + string_value="test-string-value") +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToSsmstringparameterProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.ssm.*; +import software.amazon.awsconstructs.services.lambdassmstringparameter.*; + +new LambdaToSsmstringparameter(this, "test-lambda-ssmstringparameter-stack", + new LambdaToSsmstringparameterProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .stringParameterProps(new StringParameterProps.Builder() + .stringValue("test-string-value") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-step-function/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-step-function/README.md index b200d9839..61c43c397 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-step-function/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-step-function/README.md @@ -22,38 +22,82 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an AWS Step Function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { LambdaToStepFunction } from '@aws-solutions-constructs/aws-lambda-step-function'; +// aws-lambda-step-function has been deprecated for CDK V2 in favor of aws-lambda-stepfunctions. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; +import * as lambda from '@aws-cdk/aws-lambda'; +import { LambdaToStepFunction } from '@aws-solutions-constructs/aws-lambda-step-function'; -const startState = new stepfunctions.Pass(stack, 'StartState'); +const startState = new stepfunctions.Pass(this, 'StartState'); new LambdaToStepFunction(this, 'LambdaToStepFunctionPattern', { lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) }, stateMachineProps: { definition: startState } }); - ``` -## Initializer - -``` text -new LambdaToStepFunction(scope: Construct, id: string, props: LambdaToStepFunctionProps); +Python +``` python +# aws-lambda-step-function has been deprecated for CDK V2 in favor of aws-lambda-stepfunctions. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_lambda_step_function import LambdaToStepFunction +from aws_cdk import ( + aws_lambda as _lambda, + aws_stepfunctions as stepfunctions, + core +) + +start_state = stepfunctions.Pass(self, 'start_state') + +LambdaToStepFunction( + self, 'test-lambda-stepfunctions-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + state_machine_props=stepfunctions.StateMachineProps( + definition=start_state) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToStepFunctionProps`](#pattern-construct-props) +Java +``` java +// aws-lambda-step-function has been deprecated for CDK V2 in favor of aws-lambda-stepfunctions. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.lambdastepfunction.*; + +final Pass startState = new Pass(this, "StartState"); + +new LambdaToStepFunction(this, "test-lambda-stepfunctions-stack", + new LambdaToStepFunctionProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/README.md b/source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/README.md index cd3b88320..594c34904 100644 --- a/source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/README.md @@ -20,38 +20,79 @@ This AWS Solutions Construct implements an AWS Lambda function connected to an AWS Step Functions. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { LambdaToStepfunctions } from '@aws-solutions-constructs/aws-lambda-stepfunctions'; -import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; +import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; -const startState = new stepfunctions.Pass(stack, 'StartState'); +const startState = new stepfunctions.Pass(this, 'StartState'); new LambdaToStepfunctions(this, 'LambdaToStepfunctionsPattern', { lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) }, stateMachineProps: { definition: startState } }); - ``` -## Initializer - -``` text -new LambdaToStepfunctions(scope: Construct, id: string, props: LambdaToStepfunctionsProps); +Python +```python +from aws_solutions_constructs.aws_lambda_stepfunctions import LambdaToStepfunctions +from aws_cdk import ( + aws_lambda as _lambda, + aws_stepfunctions as stepfunctions, + Stack +) +from constructs import Construct + +start_state = stepfunctions.Pass(self, 'start_state') + +LambdaToStepfunctions( + self, 'test-lambda-stepfunctions-stack', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ), + state_machine_props=stepfunctions.StateMachineProps( + definition=start_state) +) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`LambdaToStepfunctionsProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.lambdastepfunctions.*; + +final Pass startState = new Pass(this, "StartState"); + +new LambdaToStepfunctions(this, "test-lambda-stepfunctions-stack", + new LambdaToStepfunctionsProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-route53-alb/README.md b/source/patterns/@aws-solutions-constructs/aws-route53-alb/README.md index ecb9a4b7b..d2f3e1736 100644 --- a/source/patterns/@aws-solutions-constructs/aws-route53-alb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-route53-alb/README.md @@ -24,31 +24,72 @@ This AWS Solutions Construct implements an Amazon Route53 Hosted Zone routing to an Application Load Balancer -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { Route53ToAlb } from '@aws-solutions-constructs/aws-route53-alb'; +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, 'id', {env: {account: '123456789012', region: 'us-east-1' }}); new Route53ToAlb(this, 'Route53ToAlbPattern', { privateHostedZoneProps: { zoneName: 'www.example.com', - } + }, publicApi: false, }); - ``` -## Initializer - -``` text -new Route53ToAlb(scope: Construct, id: string, props: Route53ToAlbProps); +Python +```python +from aws_solutions_constructs.aws_route53_alb import Route53ToAlb +from aws_cdk import ( + aws_route53 as route53, + Stack +) +from constructs import Construct + +# Note - all alb constructs turn on ELB logging by default, so require that an environment including account +# and region be provided when creating the stack +# +# MyStack(app, 'id', env=cdk.Environment(account='679431688440', region='us-east-1')) +Route53ToAlb(self, 'Route53ToAlbPattern', + public_api=False, + private_hosted_zone_props=route53.HostedZoneProps( + zone_name='www.example.com', + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`Route53ToAlbProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.route53.*; +import software.amazon.awsconstructs.services.route53alb.*; + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, "id", StackProps.builder() +// .env(Environment.builder() +// .account("123456789012") +// .region("us-east-1") +// .build()); +new Route53ToAlb(this, "Route53ToAlbPattern", + new Route53ToAlbProps.Builder() + .privateHostedZoneProps(new HostedZoneProps.Builder() + .zoneName("www.example.com") + .build()) + .publicApi(false) + .build()); +``` ## Pattern Construct Props @@ -65,7 +106,7 @@ This construct can create Private Hosted Zones. If you want a Private Hosted Zon | vpcProps? | [ec2.VpcProps](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.VpcProps.html) | Optional custom properties for a VPC the construct will create. This VPC will be used by the new ALB and any Private Hosted Zone the construct creates (that's why loadBalancerProps and privateHostedZoneProps can't include a VPC). Providing both this and existingVpc is an error. | | existingVpc? | [ec2.IVpc](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.IVpc.html) | An existing VPC in which to deploy the construct. Providing both this and vpcProps is an error. If the client provides an existing load balancer and/or existing Private Hosted Zone, those constructs must exist in this VPC. | | logAlbAccessLogs? | boolean| Whether to turn on Access Logs for the Application Load Balancer. Uses an S3 bucket with associated storage costs.Enabling Access Logging is a best practice. default - true | -| albLoggingBucketProps? | [s3.BucketProps](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html) | Optional properties to customize the bucket used to store the ALB Access Logs. Supplying this and setting logAccessLogs to false is an error. @default - none | +| albLoggingBucketProps? | [s3.BucketProps](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html) | Optional properties to customize the bucket used to store the ALB Access Logs. Supplying this and setting logAlbAccessLogs to false is an error. @default - none | | publicApi | boolean | Whether the construct is deploying a private or public API. This has implications for the Hosted Zone, VPC and ALB. | diff --git a/source/patterns/@aws-solutions-constructs/aws-route53-apigateway/README.md b/source/patterns/@aws-solutions-constructs/aws-route53-apigateway/README.md index 9e033fc07..19fa79403 100755 --- a/source/patterns/@aws-solutions-constructs/aws-route53-apigateway/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-route53-apigateway/README.md @@ -26,49 +26,113 @@ This AWS Solutions Construct implements an Amazon Route 53 connected to a configured Amazon API Gateway REST API. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import * as api from '@aws-cdk/aws-apigateway'; -import * as lambda from "@aws-cdk/aws-lambda"; -import * as route53 from "@aws-cdk/aws-route53"; -import { Route53ToApigateway } from '@aws-solutions-constructs/aws-route53-apigateway'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import * as route53 from "aws-cdk-lib/aws-route53"; +import * as acm from "aws-cdk-lib/aws-certificatemanager"; +import { Route53ToApiGateway } from '@aws-solutions-constructs/aws-route53-apigateway'; // The construct requires an existing REST API, this can be created in raw CDK or extracted // from a previously instantiated construct that created an API Gateway REST API const existingRestApi = previouslyCreatedApigatewayToLambdaConstruct.apiGateway; +// domainName must match existing hosted zone in your account and the existing certificate const ourHostedZone = route53.HostedZone.fromLookup(this, 'HostedZone', { domainName: "example.com", - }); +}); const certificate = acm.Certificate.fromCertificateArn( - stack, + this, "fake-cert", "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" - ); +); // This construct can only be attached to a configured API Gateway. -new Route53ToApigateway(this, 'Route53ToApigatewayPattern', { - existingApiGatewayObj: existingRestApi, +new Route53ToApiGateway(this, 'Route53ToApiGatewayPattern', { + existingApiGatewayInterface: existingRestApi, existingHostedZoneInterface: ourHostedZone, publicApi: true, existingCertificateInterface: certificate }); - ``` -## Initializer +Python +```python +from aws_solutions_constructs.aws_route53_apigateway import Route53ToApiGateway +from aws_cdk import ( + aws_route53 as route53, + aws_certificatemanager as acm, + Stack +) +from constructs import Construct + +# The construct requires an existing REST API, this can be created in raw CDK or extracted +# from a previously instantiated construct that created an API Gateway REST API +existingRestApi = previouslyCreatedApigatewayToLambdaConstruct.apiGateway + +# domain_name must match existing hosted zone in your account and the existing certificate +ourHostedZone = route53.HostedZone.from_lookup(self, 'HostedZone', + domain_name="example.com", + ) + +# Obtain a pre-existing certificate from your account +certificate = acm.Certificate.from_certificate_arn( + self, + 'existing-cert', + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012" +) + +# This construct can only be attached to a configured API Gateway. +Route53ToApiGateway(self, 'Route53ToApigatewayPattern', + existing_api_gateway_interface=existingRestApi, + existing_hosted_zone_interface=ourHostedZone, + public_api=True, + existing_certificate_interface=certificate + ) -``` text -new Route53ToApigateway(scope: Construct, id: string, props: Route53ToApigatewayProps); ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.route53.*; +import software.amazon.awscdk.services.apigateway.*; +import software.amazon.awscdk.services.certificatemanager.*; +import software.amazon.awsconstructs.services.route53apigateway.*; + +// The construct requires an existing REST API, this can be created in raw CDK +// or extracted from a previously instantiated construct that created an API +// Gateway REST API +final IRestApi existingRestApi = previouslyCreatedApigatewayToLambdaConstruct.getApiGateway(); + +// domainName must match existing hosted zone in your account and the existing certificate +final IHostedZone ourHostedZone = HostedZone.fromLookup(this, "HostedZone", + new HostedZoneProviderProps.Builder() + .domainName("example.com") + .build()); + +// Obtain a pre-existing certificate from your account +final ICertificate certificate = Certificate.fromCertificateArn( + this, + "existing-cert", + "arn:aws:acm:us-east-1:123456789012:certificate/11112222-3333-1234-1234-123456789012"); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`Route53ToApigatewayProps`](#pattern-construct-props) +// This construct can only be attached to a configured API Gateway. +new Route53ToApiGateway(this, "Route53ToApiGatewayPattern", + new Route53ToApiGatewayProps.Builder() + .existingApiGatewayInterface(existingRestApi) + .existingHostedZoneInterface(ourHostedZone) + .publicApi(true) + .existingCertificateInterface(certificate) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md index ec7a2ff1f..9a7928c7f 100644 --- a/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-s3-lambda/README.md @@ -20,32 +20,61 @@ This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS Lambda function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import * as lambda from "aws-cdk-lib/aws-lambda"; import { S3ToLambdaProps, S3ToLambda } from '@aws-solutions-constructs/aws-s3-lambda'; new S3ToLambda(this, 'test-s3-lambda', { - lambdaFunctionProps: { - code: lambda.Code.fromAsset(`${__dirname}/lambda`), - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler' - }, + lambdaFunctionProps: { + code: lambda.Code.fromAsset(`lambda`), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler' + }, }); +``` +Python +```python +from aws_solutions_constructs.aws_s3_lambda import S3ToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +S3ToLambda(self, 'test_s3_lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -## Initializer -``` text -new S3ToLambda(scope: Construct, id: string, props: S3ToLambdaProps); -``` +Java +``` java +import software.constructs.Construct; -_Parameters_ +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.s3lambda.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`S3ToLambdaProps`](#pattern-construct-props) +new S3ToLambda(this, "test-s3-lambda'", new S3ToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-s3-sqs/README.md index 2788cc214..cccfd13f5 100644 --- a/source/patterns/@aws-solutions-constructs/aws-s3-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-s3-sqs/README.md @@ -25,25 +25,37 @@ This AWS Solutions Construct implements an Amazon S3 Bucket that is configured to send notifications to an Amazon SQS queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import {S3ToSqs} from "@aws-solutions-constructs/aws-s3-sqs"; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import { S3ToSqs } from "@aws-solutions-constructs/aws-s3-sqs"; -new S3ToSqs(stack, 'S3ToSQSPattern', {}); +new S3ToSqs(this, 'S3ToSQSPattern', {}); ``` -## Initializer +Python +```python +from aws_solutions_constructs.aws_s3_sqs import S3ToSqs +from aws_cdk import Stack +from constructs import Construct -``` text -new S3ToSqs(scope: Construct, id: string, props: S3ToSqsProps); +S3ToSqs(self, 'S3ToSQSPattern') ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`S3ToSqsProps`](#pattern-construct-props) +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.s3sqs.*; + +new S3ToSqs(this, "S3ToSQSPattern", new S3ToSqsProps.Builder() + .build()); +``` ## Pattern Construct Props 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 index 76eb2fa4e..97f7416d3 100644 --- a/source/patterns/@aws-solutions-constructs/aws-s3-step-function/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-s3-step-function/README.md @@ -26,32 +26,63 @@ This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS *An alternative architecture can be built that triggers a Lambda function from S3 Event notifications using aws-s3-lambda and aws-lambda-stepfunctions. Channelling the S3 events through Lambda is less flexible than EventBridge, but is more cost effective and has lower latency.* -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +// aws-s3-step-function has been deprecated for CDK V2 in favor of aws-s3-stepfunctions. +// This sample uses the CDK V1 syntax +import * as cdk from '@aws-cdk/core'; import { S3ToStepFunction, S3ToStepFunctionProps } from '@aws-solutions-constructs/aws-s3-step-function'; import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; -const startState = new stepfunctions.Pass(stack, 'StartState'); +const startState = new stepfunctions.Pass(this, 'StartState'); new S3ToStepFunction(this, 'test-s3-step-function-stack', { - stateMachineProps: { - definition: startState - } + stateMachineProps: { + definition: startState + } }); ``` -## Initializer - -``` text -new S3ToStepFunction(scope: Construct, id: string, props: S3ToStepFunctionProps); +Python +``` python +# aws-s3-step-function has been deprecated for CDK V2 in favor of aws-s3-stepfunctions. +# This sample uses the CDK V1 syntax +from aws_solutions_constructs.aws_s3_step_function import S3ToStepFunction +from aws_cdk import ( + aws_stepfunctions as stepfunctions, + core +) + +start_state = stepfunctions.Pass(self, 'start_state') + +S3ToStepFunction( + self, 'test_s3_step_function_stack', + state_machine_props=stepfunctions.StateMachineProps( + definition=start_state) +) ``` -_Parameters_ +Java +``` java +// aws-s3-step-function has been deprecated for CDK V2 in favor of aws-s3-stepfunctions. +// This sample uses the CDK V1 syntax +import software.constructs.Construct; + +import software.amazon.awscdk.core.*; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.s3stepfunction.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`S3ToStepFunctionProps`](#pattern-construct-props) +final Pass startState = new Pass(this, "StartState"); + +new S3ToStepFunction(this, "test_s3_stepfunctions_stack", + new S3ToStepFunctionProps.Builder() + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-s3-stepfunctions/README.md b/source/patterns/@aws-solutions-constructs/aws-s3-stepfunctions/README.md index 54fcbf4b4..4650475c9 100644 --- a/source/patterns/@aws-solutions-constructs/aws-s3-stepfunctions/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-s3-stepfunctions/README.md @@ -28,13 +28,16 @@ This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS *An alternative architecture can be built that triggers a Lambda function from S3 Event notifications using aws-s3-lambda and aws-lambda-stepfunctions. Channelling the S3 events through Lambda is less flexible than EventBridge, but is more cost effective and has lower latency.* -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { S3ToStepfunctions, S3ToStepfunctionsProps } from '@aws-solutions-constructs/aws-s3-stepfunctions'; -import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; +import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions'; -const startState = new stepfunctions.Pass(stack, 'StartState'); +const startState = new stepfunctions.Pass(this, 'StartState'); new S3ToStepfunctions(this, 'test-s3-stepfunctions-stack', { stateMachineProps: { @@ -43,17 +46,42 @@ new S3ToStepfunctions(this, 'test-s3-stepfunctions-stack', { }); ``` -## Initializer - -``` text -new S3ToStepfunctions(scope: Construct, id: string, props: S3ToStepfunctionsProps); +Python +```python +from aws_solutions_constructs.aws_s3_stepfunctions import S3ToStepfunctions +from aws_cdk import ( + aws_stepfunctions as stepfunctions, + Stack +) +from constructs import Construct + +start_state = stepfunctions.Pass(self, 'start_state') + +S3ToStepfunctions( + self, 'test_s3_stepfunctions_stack', + state_machine_props=stepfunctions.StateMachineProps( + definition=start_state) +) ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.stepfunctions.*; +import software.amazon.awsconstructs.services.s3stepfunctions.*; -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`S3ToStepfunctionsProps`](#pattern-construct-props) +final Pass startState = new Pass(this, "StartState"); + +new S3ToStepfunctions(this, "test_s3_stepfunctions_stack", + new S3ToStepfunctionsProps.Builder() + .stateMachineProps(new StateMachineProps.Builder() + .definition(startState) + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md index af3df2c2a..014e6e901 100644 --- a/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-sns-lambda/README.md @@ -20,32 +20,59 @@ This AWS Solutions Construct implements an Amazon SNS connected to an AWS Lambda function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { SnsToLambda, SnsToLambdaProps } from "@aws-solutions-constructs/aws-sns-lambda"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new SnsToLambda(this, 'test-sns-lambda', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); - ``` - -## Initializer - -``` text -new SnsToLambda(scope: Construct, id: string, props: SnsToLambdaProps); +Python +```python +from aws_solutions_constructs.aws_sns_lambda import SnsToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +SnsToLambda(self, 'test_sns_lambda', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`SnsToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.snslambda.*; + +new SnsToLambda(this, "test-lambda-sqs-stack", new SnsToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-sns-sqs/README.md b/source/patterns/@aws-solutions-constructs/aws-sns-sqs/README.md index 6a6666bd4..8b851ad28 100644 --- a/source/patterns/@aws-solutions-constructs/aws-sns-sqs/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-sns-sqs/README.md @@ -24,11 +24,14 @@ This AWS Solutions Construct implements an Amazon SNS topic connected to an Amazon SQS queue. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { SnsToSqs, SnsToSqsProps } from "@aws-solutions-constructs/aws-sns-sqs"; -import * as iam from '@aws-cdk/aws-iam'; +import * as iam from 'aws-cdk-lib/aws-iam'; const snsToSqsStack = new SnsToSqs(this, 'SnsToSqsPattern', {}); @@ -41,20 +44,53 @@ const policyStatement = new iam.PolicyStatement({ }); snsToSqsStack.encryptionKey?.addToResourcePolicy(policyStatement); +``` +Python +``` python +from aws_solutions_constructs.aws_sns_sqs import SnsToSqs +from aws_cdk import ( + aws_iam as iam, + Stack +) +from constructs import Construct + +construct_stack = SnsToSqs(self, 'SnsToSqsPattern') + +policy_statement = iam.PolicyStatement( + actions=["kms:Encrypt", "kms:Decrypt"], + effect=iam.Effect.ALLOW, + principals=[iam.AccountRootPrincipal()], + resources=["*"] +) + +construct_stack.encryption_key.add_to_resource_policy(policy_statement) ``` -## Initializer +Java +``` java +import software.constructs.Construct; +import java.util.List; -``` text -new SnsToSqs(scope: Construct, id: string, props: SnsToSqsProps); -``` +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.iam.*; +import software.amazon.awsconstructs.services.snssqs.*; -_Parameters_ +final SnsToSqs constructStack = new SnsToSqs(this, "SnsToSqsPattern", + new SnsToSqsProps.Builder() + .build()); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`SnsToSqsProps`](#pattern-construct-props) +// Grant yourself permissions to use the Customer Managed KMS Key +final PolicyStatement policyStatement = PolicyStatement.Builder.create() + .actions(List.of("kms:Encrypt", "kms:Decrypt")) + .effect(Effect.ALLOW) + .principals(List.of(new AccountRootPrincipal())) + .resources(List.of("*")) + .build(); + +constructStack.getEncryptionKey().addToResourcePolicy(policyStatement); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md index ea9d952ff..26b0c177f 100644 --- a/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-sqs-lambda/README.md @@ -20,32 +20,61 @@ This AWS Solutions Construct implements an Amazon SQS queue connected to an AWS Lambda function. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { SqsToLambda, SqsToLambdaProps } from "@aws-solutions-constructs/aws-sqs-lambda"; +import * as lambda from 'aws-cdk-lib/aws-lambda'; new SqsToLambda(this, 'SqsToLambdaPattern', { lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`${__dirname}/lambda`) + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) } }); - ``` -## Initializer - -``` text -new SqsToLambda(scope: Construct, id: string, props: SqsToLambdaProps); +Python +``` python +from aws_solutions_constructs.aws_sqs_lambda import SqsToLambda +from aws_cdk import ( + aws_lambda as _lambda, + Stack +) +from constructs import Construct + + +SqsToLambda(self, 'SqsToLambdaPattern', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset('lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`SqsToLambdaProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.sqslambda.*; + +new SqsToLambda(this, "SnsToSqsPattern", new SqsToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-alb/README.md b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-alb/README.md index bbcd7e292..615d2924d 100644 --- a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-alb/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-alb/README.md @@ -26,40 +26,79 @@ ## Overview This AWS Solutions Construct implements an AWS WAF web ACL connected to an Application Load Balancer. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import { Route53ToAlb } from '@aws-solutions-constructs/aws-route53-alb'; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { WafwebaclToAlbProps, WafwebaclToAlb } from "@aws-solutions-constructs/aws-wafwebacl-alb"; -// A constructed ALB is required to be attached to the WAF Web ACL. -// In this case, we are using this construct to create one. -const r53ToAlb = new Route53ToAlb(this, 'Route53ToAlbPattern', { - privateHostedZoneProps: { - zoneName: 'www.example.com', - }, - publicApi: false, - logAccessLogs: false -}); +// Use an existing ALB, such as one created by Route53toAlb or AlbToLambda +const existingLoadBalancer = previouslyCreatedLoadBalancer + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, 'id', {env: {account: '123456789012', region: 'us-east-1' }}); +// // This construct can only be attached to a configured Application Load Balancer. new WafwebaclToAlb(this, 'test-wafwebacl-alb', { - existingLoadBalancerObj: r53ToAlb.loadBalancer + existingLoadBalancerObj: existingLoadBalancer }); ``` -## Initializer - -``` text -new WafwebaclToAlb(scope: Construct, id: string, props: WafwebaclToAlbProps); +Python +```python +from aws_solutions_constructs.aws_route53_alb import Route53ToAlb +from aws_solutions_constructs.aws_wafwebacl_alb import WafwebaclToAlbProps, WafwebaclToAlb +from aws_cdk import ( + aws_route53 as route53, + Stack +) +from constructs import Construct + +# Use an existing ALB, such as one created by Route53toAlb or AlbToLambda +existingLoadBalancer = previouslyCreatedLoadBalancer + +# Note - all alb constructs turn on ELB logging by default, so require that an environment including account +# and region be provided when creating the stack +# +# MyStack(app, 'id', env=cdk.Environment(account='679431688440', region='us-east-1')) +# +# This construct can only be attached to a configured Application Load Balancer. +WafwebaclToAlb(self, 'test_wafwebacl_alb', + existing_load_balancer_obj=existingLoadBalancer + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`WafwebaclToAlbProps`](#pattern-construct-props) - +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.route53.*; +import software.amazon.awsconstructs.services.wafwebaclalb.*; + +// Use an existing ALB, such as one created by Route53toAlb or AlbToLambda +final existingLoadBalancer = previouslyCreatedLoadBalancer + +// Note - all alb constructs turn on ELB logging by default, so require that an environment including account +// and region be provided when creating the stack +// +// new MyStack(app, "id", StackProps.builder() +// .env(Environment.builder() +// .account("123456789012") +// .region("us-east-1") +// .build()); +// +// This construct can only be attached to a configured Application Load Balancer. +new WafwebaclToAlb(this, "test-wafwebacl-alb", new WafwebaclToAlbProps.Builder() + .existingLoadBalancerObj(existingLoadBalancer) + .build()); +``` ## Pattern Construct Props | **Name** | **Type** | **Description** | diff --git a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-apigateway/README.md b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-apigateway/README.md index 4dda43370..023b166a1 100644 --- a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-apigateway/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-apigateway/README.md @@ -26,39 +26,83 @@ ## Overview This AWS Solutions Construct implements an AWS WAF web ACL connected to Amazon API Gateway REST API. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript -import * as api from '@aws-cdk/aws-apigateway'; -import * as lambda from "@aws-cdk/aws-lambda"; +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; +import * as lambda from "aws-cdk-lib/aws-lambda"; import { ApiGatewayToLambda } from '@aws-solutions-constructs/aws-apigateway-lambda'; import { WafwebaclToApiGatewayProps, WafwebaclToApiGateway } from "@aws-solutions-constructs/aws-wafwebacl-apigateway"; const apiGatewayToLambda = new ApiGatewayToLambda(this, 'ApiGatewayToLambdaPattern', { - lambdaFunctionProps: { - runtime: lambda.Runtime.NODEJS_14_X, - handler: 'index.handler', - code: lambda.Code.fromAsset(`lambda`) - } + lambdaFunctionProps: { + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + code: lambda.Code.fromAsset(`lambda`) + } }); // This construct can only be attached to a configured API Gateway. new WafwebaclToApiGateway(this, 'test-wafwebacl-apigateway', { - existingApiGatewayInterface: apiGatewayToLambda.apiGateway + existingApiGatewayInterface: apiGatewayToLambda.apiGateway }); ``` -## Initializer - -``` text -new WafwebaclToApiGateway(scope: Construct, id: string, props: WafwebaclToApiGatewayProps); +Python +``` python +from aws_solutions_constructs.aws_apigateway_lambda import ApiGatewayToLambda +from aws_solutions_constructs.aws_wafwebacl_apigateway import WafwebaclToApiGatewayProps, WafwebaclToApiGateway +from aws_cdk import ( + aws_apigateway as api, + aws_lambda as _lambda, + Stack +) +from constructs import Construct + +api_gateway_to_lambda = ApiGatewayToLambda(self, 'ApiGatewayToLambdaPattern', + lambda_function_props=_lambda.FunctionProps( + code=_lambda.Code.from_asset( + 'lambda'), + runtime=_lambda.Runtime.PYTHON_3_9, + handler='index.handler' + ) + ) + +# This construct can only be attached to a configured API Gateway. +WafwebaclToApiGateway(self, 'test_wafwebacl_apigateway', + existing_api_gateway_interface=api_gateway_to_lambda.api_gateway + ) ``` -_Parameters_ - -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`WafwebaclToApiGatewayProps`](#pattern-construct-props) +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awscdk.services.apigateway.*; +import software.amazon.awscdk.services.lambda.*; +import software.amazon.awscdk.services.lambda.Runtime; +import software.amazon.awsconstructs.services.apigatewaylambda.*; +import software.amazon.awsconstructs.services.wafwebaclapigateway.*; + +final ApiGatewayToLambda apiGatewayToLambda = new ApiGatewayToLambda(this, "ApiGatewayToLambdaPattern", + new ApiGatewayToLambdaProps.Builder() + .lambdaFunctionProps(new FunctionProps.Builder() + .runtime(Runtime.NODEJS_14_X) + .code(Code.fromAsset("lambda")) + .handler("index.handler") + .build()) + .build()); + +// This construct can only be attached to a configured Application Load +// Balancer. +new WafwebaclToApiGateway(this, "test-wafwebacl-apigateway", new WafwebaclToApiGatewayProps.Builder() + .existingApiGatewayInterface(apiGatewayToLambda.getApiGateway()) + .build()); +``` ## Pattern Construct Props diff --git a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-cloudfront/README.md b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-cloudfront/README.md index 4afc97f93..2da02e312 100644 --- a/source/patterns/@aws-solutions-constructs/aws-wafwebacl-cloudfront/README.md +++ b/source/patterns/@aws-solutions-constructs/aws-wafwebacl-cloudfront/README.md @@ -26,9 +26,12 @@ ## Overview This AWS Solutions Construct implements an AWS WAF web ACL connected to Amazon CloudFront. -Here is a minimal deployable pattern definition in Typescript: +Here is a minimal deployable pattern definition: +Typescript ``` typescript +import { Construct } from 'constructs'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { CloudFrontToS3 } from '@aws-solutions-constructs/aws-cloudfront-s3'; import { WafwebaclToCloudFront } from "@aws-solutions-constructs/aws-wafwebacl-cloudfront"; @@ -40,17 +43,39 @@ new WafwebaclToCloudFront(this, 'test-wafwebacl-cloudfront', { }); ``` -## Initializer +Python +```python +from aws_solutions_constructs.aws_cloudfront_s3 import CloudFrontToS3 +from aws_solutions_constructs.aws_wafwebacl_cloudfront import WafwebaclToCloudFront +from aws_cdk import Stack +from constructs import Construct -``` text -new WafwebaclToCloudFront(scope: Construct, id: string, props: WafwebaclToCloudFrontProps); +cloudfront_to_s3 = CloudFrontToS3(self, 'test_cloudfront_s3') + +# This construct can only be attached to a configured CloudFront. +WafwebaclToCloudFront(self, 'test_wafwebacl_cloudfront', + existing_cloud_front_web_distribution=cloudfront_to_s3.cloud_front_web_distribution + ) ``` -_Parameters_ +Java +``` java +import software.constructs.Construct; + +import software.amazon.awscdk.Stack; +import software.amazon.awscdk.StackProps; +import software.amazon.awsconstructs.services.cloudfronts3.*; +import software.amazon.awsconstructs.services.wafwebaclcloudfront.*; + +final CloudFrontToS3 cloudfrontToS3 = new CloudFrontToS3(this, "test-cloudfront-s3", + new CloudFrontToS3Props.Builder() + .build()); -* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) -* id `string` -* props [`WafwebaclToCloudFrontProps`](#pattern-construct-props) +// This construct can only be attached to a configured CloudFront. +new WafwebaclToCloudFront(this, "test-wafwebacl-cloudfront", new WafwebaclToCloudFrontProps.Builder() + .existingCloudFrontWebDistribution(cloudfrontToS3.getCloudFrontWebDistribution()) + .build()); +``` ## Pattern Construct Props @@ -81,7 +106,7 @@ Out of the box implementation of the Construct without any override will set the * AWSManagedRulesAdminProtectionRuleSet * AWSManagedRulesSQLiRuleSet - *Note that the default rules can be replaced by specifying the rules property of CfnWebACLProps* + *Note that the default rules can be replaced by specifying the rules property of CfnWebACLProps* * Send metrics to Amazon CloudWatch ### Amazon CloudFront