From bc10e6ffb6164c212336ada745923e91adb8fe05 Mon Sep 17 00:00:00 2001 From: Roger Chi Date: Tue, 9 Nov 2021 11:56:04 -0500 Subject: [PATCH 1/8] feat(stepfunctions-tasks): Support `DynamoAttributeValue.listFromJsonPath` (#17376) Add `DynamoAttributeValue.listFromJsonPath(value: string)` to allow specifying a list/array from the state input as a parameter in a DynamoDB PutItem or UpdateItem optimized integration in stepfunctions-tasks. Closes #17375 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/dynamodb/shared-types.ts | 10 ++++++++++ .../dynamodb/integ.call-dynamodb.expected.json | 2 +- .../test/dynamodb/integ.call-dynamodb.ts | 1 + .../test/dynamodb/shared-types.test.ts | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts index c07d1e8fc5e12..0921cf3b2521a 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts @@ -219,6 +219,16 @@ export class DynamoAttributeValue { return new DynamoAttributeValue({ L: value.map((val) => val.toObject()) }); } + /** + * Sets an attribute of type List. For example: "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"S", "Veggies"}] + * + * @param value Json path that specifies state input to be used + */ + public static listFromJsonPath(value: string) { + validateJsonPath(value); + return new DynamoAttributeValue({ L: value }); + } + /** * Sets an attribute of type Null. For example: "NULL": true */ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.expected.json index 094221d1ba6bb..a8b7510287767 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.expected.json @@ -193,7 +193,7 @@ { "Ref": "AWS::Partition" }, - ":states:::dynamodb:putItem\",\"Parameters\":{\"Item\":{\"MessageId\":{\"S\":\"1234\"},\"Text\":{\"S.$\":\"$.bar\"},\"TotalCount\":{\"N\":\"18\"},\"Activated\":{\"BOOL.$\":\"$.foo\"}},\"TableName\":\"", + ":states:::dynamodb:putItem\",\"Parameters\":{\"Item\":{\"MessageId\":{\"S\":\"1234\"},\"Text\":{\"S.$\":\"$.bar\"},\"TotalCount\":{\"N\":\"18\"},\"Activated\":{\"BOOL.$\":\"$.foo\"},\"List\":{\"L.$\":\"$.list\"}},\"TableName\":\"", { "Ref": "Messages804FA4EB" }, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.ts index e78bba4f6721e..18be323c22db3 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/integ.call-dynamodb.ts @@ -37,6 +37,7 @@ class CallDynamoDBStack extends cdk.Stack { Text: tasks.DynamoAttributeValue.fromString(sfn.JsonPath.stringAt('$.bar')), TotalCount: tasks.DynamoAttributeValue.fromNumber(firstNumber), Activated: tasks.DynamoAttributeValue.booleanFromJsonPath(sfn.JsonPath.stringAt('$.foo')), + List: tasks.DynamoAttributeValue.listFromJsonPath(sfn.JsonPath.stringAt('$.list')), }, table, }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/shared-types.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/shared-types.test.ts index f0810de3e3949..a882fb9f99b2b 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/shared-types.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/dynamodb/shared-types.test.ts @@ -222,6 +222,22 @@ describe('DynamoAttributeValue', () => { }); }); + test('from list with json path', () => { + // GIVEN + const m = '$.path'; + // WHEN + const attribute = tasks.DynamoAttributeValue.listFromJsonPath( + sfn.JsonPath.stringAt(m), + ); + + // THEN + expect(sfn.FieldUtils.renderObject(attribute)).toEqual({ + attributeValue: { + 'L.$': m, + }, + }); + }); + test('from null', () => { // WHEN const attribute = tasks.DynamoAttributeValue.fromNull(true); From 3154a58bfc5ae4b845994c7a0ab45771f5af4cd0 Mon Sep 17 00:00:00 2001 From: JohnLux4 <38677408+eastNine@users.noreply.github.com> Date: Wed, 10 Nov 2021 02:53:31 +0900 Subject: [PATCH 2/8] fix(autoscaling): add timezone property to Scheduled Action (#17330) Add timezone property to ScheduledAction. example: ```typescript import * as asg from '@aws-cdk/aws-autoscaling'; new asg.ScheduledAction(this, 'test', { autoScalingGroup: 'test', desiredCapacity: 1, minCapacity: 1, maxCapacity: 2, schedule: { expressionString: '0 3 * * *' }, timeZone: 'Asia/Seoul' }); ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-autoscaling/lib/scheduled-action.ts | 12 +++++++++++ .../test/scheduled-action.test.ts | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts index 70a269bde9239..fa5d431bcf47b 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts @@ -8,6 +8,17 @@ import { Schedule } from './schedule'; * Properties for a scheduled scaling action */ export interface BasicScheduledActionProps { + /** + * Specifies the time zone for a cron expression. If a time zone is not provided, UTC is used by default. + * + * Valid values are the canonical names of the IANA time zones, derived from the IANA Time Zone Database (such as Etc/GMT+9 or Pacific/Tahiti). + * + * For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. + * + * @default - UTC + * + */ + readonly timeZone?: string; /** * When to perform this action. * @@ -94,6 +105,7 @@ export class ScheduledAction extends Resource { maxSize: props.maxCapacity, desiredCapacity: props.desiredCapacity, recurrence: props.schedule.expressionString, + timeZone: props.timeZone, }); } } diff --git a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts index 3afbd887b45ae..e7aeb92a81b6d 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts @@ -46,6 +46,27 @@ describe('scheduled action', () => { }); + test('have timezone property', () => { + // GIVEN + const stack = new cdk.Stack(); + const asg = makeAutoScalingGroup(stack); + + // WHEN + asg.scaleOnSchedule('ScaleOutAtMiddaySeoul', { + schedule: autoscaling.Schedule.cron({ hour: '12', minute: '0' }), + minCapacity: 12, + timeZone: 'Asia/Seoul', + }); + + // THEN + expect(stack).to(haveResource('AWS::AutoScaling::ScheduledAction', { + MinSize: 12, + Recurrence: '0 12 * * *', + TimeZone: 'Asia/Seoul', + })); + + }); + test('autoscaling group has recommended updatepolicy for scheduled actions', () => { // GIVEN const stack = new cdk.Stack(); From bde44e7a767b88762ecb1370e605e6e5dfc85b52 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Tue, 9 Nov 2021 18:31:00 +0000 Subject: [PATCH 3/8] feat(assertions): support assertions over nested stacks (#16972) Add support for nested stacks ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- package.json | 4 + packages/@aws-cdk/assertions/NOTICE | 88 ++++++++++++++++++- packages/@aws-cdk/assertions/lib/template.ts | 6 ++ packages/@aws-cdk/assertions/package.json | 7 +- .../@aws-cdk/assertions/test/template.test.ts | 44 ++++++++-- 5 files changed, 138 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6f8bbee09c04f..aea497b0788f1 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,10 @@ "nohoist": [ "**/jszip", "**/jszip/**", + "@aws-cdk/assertions-alpha/fs-extra", + "@aws-cdk/assertions-alpha/fs-extra/**", + "@aws-cdk/assertions/fs-extra", + "@aws-cdk/assertions/fs-extra/**", "@aws-cdk/aws-amplify-alpha/yaml", "@aws-cdk/aws-amplify-alpha/yaml/**", "@aws-cdk/aws-amplify/yaml", diff --git a/packages/@aws-cdk/assertions/NOTICE b/packages/@aws-cdk/assertions/NOTICE index ac712780ec5ca..9e3fd34dbe209 100644 --- a/packages/@aws-cdk/assertions/NOTICE +++ b/packages/@aws-cdk/assertions/NOTICE @@ -1,2 +1,88 @@ AWS Cloud Development Kit (AWS CDK) -Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file +Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +------------------------------------------------------------------------------- + +The AWS CDK includes the following third-party software/licensing: + +** fs-extra - https://www.npmjs.com/package/fs-extra +Copyright (c) 2011-2017 JP Richardson + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +---------------- + +** at-least-node - https://www.npmjs.com/package/at-least-node +Copyright (c) 2020 Ryan Zimmerman + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +---------------- + +** graceful-fs - https://www.npmjs.com/package/graceful-fs +Copyright (c) Isaac Z. Schlueter, Ben Noordhuis, and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +---------------- + +** jsonfile - https://www.npmjs.com/package/jsonfile +Copyright (c) 2012-2015, JP Richardson + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +---------------- + +** universalify - https://www.npmjs.com/package/universalify +Copyright (c) 2017, Ryan Zimmerman + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the 'Software'), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +---------------- \ No newline at end of file diff --git a/packages/@aws-cdk/assertions/lib/template.ts b/packages/@aws-cdk/assertions/lib/template.ts index 01e0d3376dc8c..dfc830cf8d822 100644 --- a/packages/@aws-cdk/assertions/lib/template.ts +++ b/packages/@aws-cdk/assertions/lib/template.ts @@ -1,4 +1,6 @@ +import * as path from 'path'; import { Stack, Stage } from '@aws-cdk/core'; +import * as fs from 'fs-extra'; import { Match } from './match'; import { Matcher } from './matcher'; import { findMappings, hasMapping } from './private/mappings'; @@ -179,5 +181,9 @@ function toTemplate(stack: Stack): any { throw new Error('unexpected: all stacks must be part of a Stage or an App'); } const assembly = root.synth(); + if (stack.nestedStackParent) { + // if this is a nested stack (it has a parent), then just read the template as a string + return JSON.parse(fs.readFileSync(path.join(assembly.directory, stack.templateFile)).toString('utf-8')); + } return assembly.getStackArtifact(stack.artifactId).template; } \ No newline at end of file diff --git a/packages/@aws-cdk/assertions/package.json b/packages/@aws-cdk/assertions/package.json index 2e814d423cacd..35e2842a2bd0c 100644 --- a/packages/@aws-cdk/assertions/package.json +++ b/packages/@aws-cdk/assertions/package.json @@ -64,6 +64,7 @@ "devDependencies": { "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/pkglint": "0.0.0", + "@types/fs-extra": "^9.0.13", "@types/jest": "^27.0.2", "constructs": "^3.3.69", "jest": "^27.3.1", @@ -73,7 +74,8 @@ "@aws-cdk/cloud-assembly-schema": "0.0.0", "@aws-cdk/core": "0.0.0", "@aws-cdk/cx-api": "0.0.0", - "constructs": "^3.3.69" + "constructs": "^3.3.69", + "fs-extra": "^9.1.0" }, "peerDependencies": { "@aws-cdk/cloud-assembly-schema": "0.0.0", @@ -81,6 +83,9 @@ "@aws-cdk/cx-api": "0.0.0", "constructs": "^3.3.69" }, + "bundledDependencies": [ + "fs-extra" + ], "repository": { "url": "https://github.com/aws/aws-cdk.git", "type": "git", diff --git a/packages/@aws-cdk/assertions/test/template.test.ts b/packages/@aws-cdk/assertions/test/template.test.ts index 3384cda21207f..64141edf52e89 100644 --- a/packages/@aws-cdk/assertions/test/template.test.ts +++ b/packages/@aws-cdk/assertions/test/template.test.ts @@ -1,11 +1,10 @@ -import { App, CfnMapping, CfnOutput, CfnResource, Stack } from '@aws-cdk/core'; +import { App, CfnMapping, CfnOutput, CfnResource, NestedStack, Stack } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { Match, Template } from '../lib'; describe('Template', () => { - describe('asObject', () => { - test('fromString', () => { - const template = Template.fromString(`{ + test('fromString', () => { + const template = Template.fromString(`{ "Resources": { "Foo": { "Type": "Baz::Qux", @@ -14,30 +13,57 @@ describe('Template', () => { } }`); + expect(template.toJSON()).toEqual({ + Resources: { + Foo: { + Type: 'Baz::Qux', + Properties: { Fred: 'Waldo' }, + }, + }, + }); + }); + + describe('fromStack', () => { + test('default', () => { + const app = new App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + const stack = new Stack(app); + new CfnResource(stack, 'Foo', { + type: 'Foo::Bar', + properties: { + Baz: 'Qux', + }, + }); + const template = Template.fromStack(stack); + expect(template.toJSON()).toEqual({ Resources: { Foo: { - Type: 'Baz::Qux', - Properties: { Fred: 'Waldo' }, + Type: 'Foo::Bar', + Properties: { Baz: 'Qux' }, }, }, }); }); - test('fromStack', () => { + test('nested', () => { const app = new App({ context: { '@aws-cdk/core:newStyleStackSynthesis': false, }, }); const stack = new Stack(app); - new CfnResource(stack, 'Foo', { + const nested = new NestedStack(stack, 'MyNestedStack'); + new CfnResource(nested, 'Foo', { type: 'Foo::Bar', properties: { Baz: 'Qux', }, }); - const template = Template.fromStack(stack); + const template = Template.fromStack(nested); expect(template.toJSON()).toEqual({ Resources: { From acd64f4f23840e51ba432934b9d1377c1ed46ef2 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 9 Nov 2021 20:11:57 +0100 Subject: [PATCH 4/8] docs: re-enable example 'strict' mode where possible (#17421) This will prevent regression in compilation status for the top 25 construct libraries, that we've gone through the effort of making compile. This also gets rid of the `@example` values in most of the construct libraries here. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/assertions/package.json | 2 +- packages/@aws-cdk/aws-apigateway/package.json | 9 +++- .../aws-apigatewayv2-authorizers/package.json | 9 +++- .../aws-apigatewayv2-integrations/README.md | 13 +++--- .../package.json | 9 +++- .../lib/scalable-target.ts | 8 ++-- .../lib/target-tracking-scaling-policy.ts | 2 +- .../aws-applicationautoscaling/package.json | 9 +++- .../aws-appmesh/lib/virtual-service.ts | 2 +- packages/@aws-cdk/aws-appmesh/package.json | 9 +++- packages/@aws-cdk/aws-appsync/package.json | 9 +++- .../@aws-cdk/aws-autoscaling/package.json | 9 +++- packages/@aws-cdk/aws-cloudwatch/package.json | 9 +++- packages/@aws-cdk/aws-codebuild/README.md | 2 +- .../aws-codebuild/lib/file-location.ts | 3 +- packages/@aws-cdk/aws-codebuild/package.json | 9 +++- .../aws-codepipeline-actions/README.md | 2 +- .../aws-codepipeline-actions/package.json | 9 +++- packages/@aws-cdk/aws-dynamodb/package.json | 9 +++- packages/@aws-cdk/aws-ec2/package.json | 9 +++- packages/@aws-cdk/aws-ecr/package.json | 9 +++- .../@aws-cdk/aws-ecs-patterns/package.json | 9 +++- packages/@aws-cdk/aws-ecs/package.json | 9 +++- .../lib/shared/base-load-balancer.ts | 21 ++++++--- .../lib/shared/base-target-group.ts | 2 +- .../aws-elasticloadbalancingv2/package.json | 9 +++- .../@aws-cdk/aws-events-targets/package.json | 9 +++- packages/@aws-cdk/aws-events/package.json | 9 +++- packages/@aws-cdk/aws-iam/package.json | 9 +++- packages/@aws-cdk/aws-kms/package.json | 9 +++- packages/@aws-cdk/aws-lambda/package.json | 9 +++- packages/@aws-cdk/aws-logs/README.md | 27 +++--------- packages/@aws-cdk/aws-logs/package.json | 9 +++- .../aws-logs/rosetta/default.ts-fixture | 1 + packages/@aws-cdk/aws-rds/package.json | 9 +++- .../aws-route53-patterns/package.json | 9 +++- .../@aws-cdk/aws-route53-targets/README.md | 21 +++++---- .../@aws-cdk/aws-route53-targets/package.json | 9 +++- packages/@aws-cdk/aws-route53/package.json | 9 +++- packages/@aws-cdk/aws-s3/lib/bucket.ts | 44 +++++++++++-------- packages/@aws-cdk/aws-s3/package.json | 9 +++- .../aws-sns-subscriptions/package.json | 9 +++- packages/@aws-cdk/aws-sns/package.json | 9 +++- packages/@aws-cdk/aws-sqs/package.json | 9 +++- packages/@aws-cdk/aws-ssm/package.json | 9 +++- .../lib/athena/get-query-execution.ts | 2 +- .../lib/athena/get-query-results.ts | 4 +- .../lib/athena/start-query-execution.ts | 3 +- .../lib/dynamodb/shared-types.ts | 6 +-- .../lib/evaluate-expression.ts | 2 +- .../lib/eventbridge/put-events.ts | 10 +++-- .../aws-stepfunctions-tasks/package.json | 9 +++- .../aws-stepfunctions/lib/states/wait.ts | 6 +-- .../@aws-cdk/aws-stepfunctions/package.json | 9 +++- packages/@aws-cdk/aws-synthetics/package.json | 9 +++- .../lib/blueprint/stack-deployment.ts | 2 +- packages/@aws-cdk/pipelines/package.json | 9 +++- 57 files changed, 375 insertions(+), 125 deletions(-) diff --git a/packages/@aws-cdk/assertions/package.json b/packages/@aws-cdk/assertions/package.json index 35e2842a2bd0c..1b515143d4d58 100644 --- a/packages/@aws-cdk/assertions/package.json +++ b/packages/@aws-cdk/assertions/package.json @@ -50,7 +50,7 @@ "metadata": { "jsii": { "rosetta": { - "strict": false + "strict": true } } } diff --git a/packages/@aws-cdk/aws-apigateway/package.json b/packages/@aws-cdk/aws-apigateway/package.json index 0901cd7438a7b..d20ad7f17d5f5 100644 --- a/packages/@aws-cdk/aws-apigateway/package.json +++ b/packages/@aws-cdk/aws-apigateway/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers/package.json b/packages/@aws-cdk/aws-apigatewayv2-authorizers/package.json index 67b23ee362f5a..8465cb5e8a9a5 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers/package.json +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers/package.json @@ -30,7 +30,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md b/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md index dc29843d00209..d284be9491e99 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md @@ -172,7 +172,7 @@ The following example creates a new header - `header2` - as a copy of `header1` ```ts import { HttpAlbIntegration } from '@aws-cdk/aws-apigatewayv2-integrations'; -declare const lb: elbv2.NetworkLoadBalancer; +declare const lb: elbv2.ApplicationLoadBalancer; const listener = lb.addListener('listener', { port: 80 }); listener.addTargets('target', { port: 80, @@ -182,9 +182,8 @@ const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', { defaultIntegration: new HttpAlbIntegration({ listener, parameterMapping: new apigwv2.ParameterMapping() - .appendHeader('header2', apigwv2.MappingValue.header('header1')) + .appendHeader('header2', apigwv2.MappingValue.requestHeader('header1')) .removeHeader('header1'), - }), }), }); ``` @@ -194,7 +193,7 @@ To add mapping keys and values not yet supported by the CDK, use the `custom()` ```ts import { HttpAlbIntegration } from '@aws-cdk/aws-apigatewayv2-integrations'; -declare const lb: elbv2.NetworkLoadBalancer; +declare const lb: elbv2.ApplicationLoadBalancer; const listener = lb.addListener('listener', { port: 80 }); listener.addTargets('target', { port: 80, @@ -203,9 +202,7 @@ listener.addTargets('target', { const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', { defaultIntegration: new HttpAlbIntegration({ listener, - parameterMapping: new apigwv2.ParameterMapping() - .custom('myKey', 'myValue'), - }), + parameterMapping: new apigwv2.ParameterMapping().custom('myKey', 'myValue'), }), }); ``` @@ -217,7 +214,7 @@ WebSocket integrations connect a route to backend resources. The following integ ### Lambda WebSocket Integration -Lambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects +Lambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects or sends message specific to a route, the API Gateway service forwards the request to the Lambda function The API Gateway service will invoke the lambda function with an event payload of a specific format. diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json b/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json index 10cde741e9d26..203793018a92a 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts index ca5f973a8fa50..7937b331c018a 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts @@ -39,7 +39,8 @@ export interface ScalableTargetProps { * * This string consists of the resource type and unique identifier. * - * @example service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH + * Example value: `service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH` + * * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_RegisterScalableTarget.html */ readonly resourceId: string; @@ -49,7 +50,7 @@ export interface ScalableTargetProps { * * Specify the service namespace, resource type, and scaling property. * - * @example ecs:service:DesiredCount + * Example value: `ecs:service:DesiredCount` * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_ScalingPolicy.html */ readonly scalableDimension: string; @@ -82,7 +83,8 @@ export class ScalableTarget extends Resource implements IScalableTarget { /** * ID of the Scalable Target * - * @example service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs + * Example value: `service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs` + * * @attribute */ public readonly scalableTargetId: string; diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts index f7ccaff153ffe..de48ab5fd21e7 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts @@ -88,7 +88,7 @@ export interface BasicTargetTrackingScalingPolicyProps extends BaseTargetTrackin * * Only used for predefined metric ALBRequestCountPerTarget. * - * @example app///targetgroup// + * Example value: `app///targetgroup//` * * @default - No resource label. */ diff --git a/packages/@aws-cdk/aws-applicationautoscaling/package.json b/packages/@aws-cdk/aws-applicationautoscaling/package.json index ca025554d085f..17bfd09967f88 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/package.json +++ b/packages/@aws-cdk/aws-applicationautoscaling/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-appmesh/lib/virtual-service.ts b/packages/@aws-cdk/aws-appmesh/lib/virtual-service.ts index cb561eff19308..a75989bbbe66a 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/virtual-service.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/virtual-service.ts @@ -40,7 +40,7 @@ export interface VirtualServiceProps { * It is recommended this follows the fully-qualified domain name format, * such as "my-service.default.svc.cluster.local". * - * @example service.domain.local + * Example value: `service.domain.local` * @default - A name is automatically generated */ readonly virtualServiceName?: string; diff --git a/packages/@aws-cdk/aws-appmesh/package.json b/packages/@aws-cdk/aws-appmesh/package.json index a7024d16cbc9b..0bf1fc94a030d 100644 --- a/packages/@aws-cdk/aws-appmesh/package.json +++ b/packages/@aws-cdk/aws-appmesh/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index f36a7ada3d7ec..814bfb98e9600 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-autoscaling/package.json b/packages/@aws-cdk/aws-autoscaling/package.json index 0fd6ce84bf75c..dfdb08ad1ac2b 100644 --- a/packages/@aws-cdk/aws-autoscaling/package.json +++ b/packages/@aws-cdk/aws-autoscaling/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-cloudwatch/package.json b/packages/@aws-cdk/aws-cloudwatch/package.json index 5466e925c6663..b02f9e882b51a 100644 --- a/packages/@aws-cdk/aws-cloudwatch/package.json +++ b/packages/@aws-cdk/aws-cloudwatch/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 29d06892bc682..4bccbbc68cfa1 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -243,7 +243,7 @@ new codebuild.Project(this, 'Project', { }), // Enable Docker AND custom caching - cache: codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM) + cache: codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM), // BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can // also come from 'buildspec.yml' in your source. diff --git a/packages/@aws-cdk/aws-codebuild/lib/file-location.ts b/packages/@aws-cdk/aws-codebuild/lib/file-location.ts index eabfd95570b06..b836fc92bc22a 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/file-location.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/file-location.ts @@ -71,7 +71,8 @@ export interface EfsFileSystemLocationProps { /** * A string that specifies the location of the file system, like Amazon EFS. - * @example 'fs-abcd1234.efs.us-west-2.amazonaws.com:/my-efs-mount-directory'. + * + * This value looks like `fs-abcd1234.efs.us-west-2.amazonaws.com:/my-efs-mount-directory`. */ readonly location: string; diff --git a/packages/@aws-cdk/aws-codebuild/package.json b/packages/@aws-cdk/aws-codebuild/package.json index 50ac7d24ef78a..05c5e55339acb 100644 --- a/packages/@aws-cdk/aws-codebuild/package.json +++ b/packages/@aws-cdk/aws-codebuild/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-codepipeline-actions/README.md b/packages/@aws-cdk/aws-codepipeline-actions/README.md index 05860cfe20233..7625ed08bfb8e 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/README.md +++ b/packages/@aws-cdk/aws-codepipeline-actions/README.md @@ -987,7 +987,7 @@ The Lambda Action supports custom user parameters that pipeline will pass to the Lambda function: ```ts -import * as lambda from '@aws-cdk/aws-lambda'; +declare const fn: lambda.Function; const pipeline = new codepipeline.Pipeline(this, 'MyPipeline'); const lambdaAction = new codepipeline_actions.LambdaInvokeAction({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/package.json b/packages/@aws-cdk/aws-codepipeline-actions/package.json index f1624f676dc9c..dc2c146e3ddd7 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/package.json +++ b/packages/@aws-cdk/aws-codepipeline-actions/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-dynamodb/package.json b/packages/@aws-cdk/aws-dynamodb/package.json index f1fdf012ab0b8..d63167cf3d5de 100644 --- a/packages/@aws-cdk/aws-dynamodb/package.json +++ b/packages/@aws-cdk/aws-dynamodb/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-ec2/package.json b/packages/@aws-cdk/aws-ec2/package.json index f8664e445ec97..44347facefb48 100644 --- a/packages/@aws-cdk/aws-ec2/package.json +++ b/packages/@aws-cdk/aws-ec2/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-ecr/package.json b/packages/@aws-cdk/aws-ecr/package.json index 704de9272f366..c9039866abcc0 100644 --- a/packages/@aws-cdk/aws-ecr/package.json +++ b/packages/@aws-cdk/aws-ecr/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-ecs-patterns/package.json b/packages/@aws-cdk/aws-ecs-patterns/package.json index e399ff853d46b..96a5eccecc75f 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/package.json +++ b/packages/@aws-cdk/aws-ecs-patterns/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-ecs/package.json b/packages/@aws-cdk/aws-ecs/package.json index 7cdcc0b9b0934..dc6c57ffe9285 100644 --- a/packages/@aws-cdk/aws-ecs/package.json +++ b/packages/@aws-cdk/aws-ecs/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index bcf51d4d81a78..85ae9d143f0e2 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -52,16 +52,18 @@ export interface ILoadBalancerV2 extends IResource { /** * The canonical hosted zone ID of this load balancer * + * Example value: `Z2P70J7EXAMPLE` + * * @attribute - * @example Z2P70J7EXAMPLE */ readonly loadBalancerCanonicalHostedZoneId: string; /** * The DNS name of this load balancer * + * Example value: `my-load-balancer-424835706.us-west-2.elb.amazonaws.com` + * * @attribute - * @example my-load-balancer-424835706.us-west-2.elb.amazonaws.com */ readonly loadBalancerDnsName: string; } @@ -141,40 +143,45 @@ export abstract class BaseLoadBalancer extends Resource { /** * The canonical hosted zone ID of this load balancer * + * Example value: `Z2P70J7EXAMPLE` + * * @attribute - * @example Z2P70J7EXAMPLE */ public readonly loadBalancerCanonicalHostedZoneId: string; /** * The DNS name of this load balancer * + * Example value: `my-load-balancer-424835706.us-west-2.elb.amazonaws.com` + * * @attribute - * @example my-load-balancer-424835706.us-west-2.elb.amazonaws.com */ public readonly loadBalancerDnsName: string; /** * The full name of this load balancer * + * Example value: `app/my-load-balancer/50dc6c495c0c9188` + * * @attribute - * @example app/my-load-balancer/50dc6c495c0c9188 */ public readonly loadBalancerFullName: string; /** * The name of this load balancer * + * Example value: `my-load-balancer` + * * @attribute - * @example my-load-balancer */ public readonly loadBalancerName: string; /** * The ARN of this load balancer * + * Example value: `arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-internal-load-balancer/50dc6c495c0c9188` + * * @attribute - * @example arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-internal-load-balancer/50dc6c495c0c9188 */ public readonly loadBalancerArn: string; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 29a9cb707556e..69d925bc933e9 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -186,7 +186,7 @@ export abstract class TargetGroupBase extends CoreConstruct implements ITargetGr * This identifier is emitted as a dimensions of the metrics of this target * group. * - * @example app/my-load-balancer/123456789 + * Example value: `app/my-load-balancer/123456789` */ public abstract readonly firstLoadBalancerFullName: string; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json index f7f5546a41b05..d2a9b352b4163 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-events-targets/package.json b/packages/@aws-cdk/aws-events-targets/package.json index e937e5c40ac4b..c59f621de9d2b 100644 --- a/packages/@aws-cdk/aws-events-targets/package.json +++ b/packages/@aws-cdk/aws-events-targets/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-events/package.json b/packages/@aws-cdk/aws-events/package.json index fb10cafd5c60b..7159bada50ee2 100644 --- a/packages/@aws-cdk/aws-events/package.json +++ b/packages/@aws-cdk/aws-events/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-iam/package.json b/packages/@aws-cdk/aws-iam/package.json index 7fda5ccefad3d..e448eaf64cec0 100644 --- a/packages/@aws-cdk/aws-iam/package.json +++ b/packages/@aws-cdk/aws-iam/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-kms/package.json b/packages/@aws-cdk/aws-kms/package.json index 66a47be7c03da..e38c467b3b4f7 100644 --- a/packages/@aws-cdk/aws-kms/package.json +++ b/packages/@aws-cdk/aws-kms/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-lambda/package.json b/packages/@aws-cdk/aws-lambda/package.json index b966e65d20c98..6afda74f971fc 100644 --- a/packages/@aws-cdk/aws-lambda/package.json +++ b/packages/@aws-cdk/aws-lambda/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-logs/README.md b/packages/@aws-cdk/aws-logs/README.md index 631bc382365e0..804b5c56c4eb3 100644 --- a/packages/@aws-cdk/aws-logs/README.md +++ b/packages/@aws-cdk/aws-logs/README.md @@ -51,14 +51,11 @@ publish their log group to a specific region, such as AWS Chatbot creating a log ## Resource Policy CloudWatch Resource Policies allow other AWS services or IAM Principals to put log events into the log groups. -A resource policy is automatically created when `addToResourcePolicy` is called on the LogGroup for the first time. - -`ResourcePolicy` can also be created manually. +A resource policy is automatically created when `addToResourcePolicy` is called on the LogGroup for the first time: ```ts -const logGroup = new LogGroup(this, 'LogGroup'); -const resourcePolicy = new ResourcePolicy(this, 'ResourcePolicy'); -resourcePolicy.document.addStatements(new iam.PolicyStatement({ +const logGroup = new logs.LogGroup(this, 'LogGroup'); +logGroup.addToResourcePolicy(new iam.PolicyStatement({ actions: ['logs:CreateLogStream', 'logs:PutLogEvents'], principals: [new iam.ServicePrincipal('es.amazonaws.com')], resources: [logGroup.logGroupArn], @@ -68,22 +65,8 @@ resourcePolicy.document.addStatements(new iam.PolicyStatement({ Or more conveniently, write permissions to the log group can be granted as follows which gives same result as in the above example. ```ts -const logGroup = new LogGroup(this, 'LogGroup'); -logGroup.grantWrite(iam.ServicePrincipal('es.amazonaws.com')); -``` - -Optionally name and policy statements can also be passed on `ResourcePolicy` construction. - -```ts -const policyStatement = new new iam.PolicyStatement({ - resources: ["*"], - actions: ['logs:PutLogEvents'], - principals: [new iam.ArnPrincipal('arn:aws:iam::123456789012:user/user-name')], -}); -const resourcePolicy = new ResourcePolicy(this, 'ResourcePolicy', { - policyName: 'myResourcePolicy', - policyStatements: [policyStatement], -}); +const logGroup = new logs.LogGroup(this, 'LogGroup'); +logGroup.grantWrite(new iam.ServicePrincipal('es.amazonaws.com')); ``` ## Encrypting Log Groups diff --git a/packages/@aws-cdk/aws-logs/package.json b/packages/@aws-cdk/aws-logs/package.json index 5c1d328a6f6bb..9169d12ac72fe 100644 --- a/packages/@aws-cdk/aws-logs/package.json +++ b/packages/@aws-cdk/aws-logs/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-logs/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-logs/rosetta/default.ts-fixture index 27c338ce30a32..6c34f60674f19 100644 --- a/packages/@aws-cdk/aws-logs/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-logs/rosetta/default.ts-fixture @@ -2,6 +2,7 @@ import { Construct } from 'constructs'; import { Stack } from '@aws-cdk/core'; import * as logs from '@aws-cdk/aws-logs'; +import * as iam from '@aws-cdk/aws-iam'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as lambda from '@aws-cdk/aws-lambda'; diff --git a/packages/@aws-cdk/aws-rds/package.json b/packages/@aws-cdk/aws-rds/package.json index b1bf50b500a40..a9c66bfb3f081 100644 --- a/packages/@aws-cdk/aws-rds/package.json +++ b/packages/@aws-cdk/aws-rds/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-route53-patterns/package.json b/packages/@aws-cdk/aws-route53-patterns/package.json index 7f3d2c396ede3..d8c12460322a6 100644 --- a/packages/@aws-cdk/aws-route53-patterns/package.json +++ b/packages/@aws-cdk/aws-route53-patterns/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-route53-targets/README.md b/packages/@aws-cdk/aws-route53-targets/README.md index 9d53630628ddd..73269abb6d6ed 100644 --- a/packages/@aws-cdk/aws-route53-targets/README.md +++ b/packages/@aws-cdk/aws-route53-targets/README.md @@ -58,7 +58,7 @@ This library contains Route53 Alias Record targets for: ```ts import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; - + declare const zone: route53.HostedZone; declare const lb: elbv2.ApplicationLoadBalancer; @@ -73,7 +73,7 @@ This library contains Route53 Alias Record targets for: ```ts import * as elb from '@aws-cdk/aws-elasticloadbalancing'; - + declare const zone: route53.HostedZone; declare const lb: elb.LoadBalancer; @@ -129,7 +129,7 @@ See [the Developer Guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGu ```ts import * as s3 from '@aws-cdk/aws-s3'; - + const recordName = 'www'; const domainName = 'example.com'; @@ -176,11 +176,14 @@ See [the Developer Guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGu **Important:** Only supports Elastic Beanstalk environments created after 2016 that have a regional endpoint. - ```ts - new route53.ARecord(this, 'AliasRecord', { - zone, - target: route53.RecordTarget.fromAlias(new alias.ElasticBeanstalkEnvironmentEndpointTarget(ebsEnvironmentUrl)), - }); - ``` +```ts +declare const zone: route53.HostedZone; +declare const ebsEnvironmentUrl: string; + +new route53.ARecord(this, 'AliasRecord', { + zone, + target: route53.RecordTarget.fromAlias(new targets.ElasticBeanstalkEnvironmentEndpointTarget(ebsEnvironmentUrl)), +}); +``` See the documentation of `@aws-cdk/aws-route53` for more information. diff --git a/packages/@aws-cdk/aws-route53-targets/package.json b/packages/@aws-cdk/aws-route53-targets/package.json index cd191bfc3173e..a65e4a0372abf 100644 --- a/packages/@aws-cdk/aws-route53-targets/package.json +++ b/packages/@aws-cdk/aws-route53-targets/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-route53/package.json b/packages/@aws-cdk/aws-route53/package.json index 35c3abefcc477..aabd22c95363b 100644 --- a/packages/@aws-cdk/aws-route53/package.json +++ b/packages/@aws-cdk/aws-route53/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 157aa31a3ed5f..ce8dafd5a69aa 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -105,9 +105,10 @@ export interface IBucket extends IResource { /** * The https URL of an S3 object. For example: - * @example https://s3.us-west-1.amazonaws.com/onlybucket - * @example https://s3.us-west-1.amazonaws.com/bucket/key - * @example https://s3.cn-north-1.amazonaws.com.cn/china-bucket/mykey + * + * - `https://s3.us-west-1.amazonaws.com/onlybucket` + * - `https://s3.us-west-1.amazonaws.com/bucket/key` + * - `https://s3.cn-north-1.amazonaws.com.cn/china-bucket/mykey` * @param key The S3 key of the object. If not specified, the URL of the * bucket is returned. * @returns an ObjectS3Url token @@ -117,10 +118,11 @@ export interface IBucket extends IResource { /** * The virtual hosted-style URL of an S3 object. Specify `regional: false` at * the options for non-regional URL. For example: - * @example https://only-bucket.s3.us-west-1.amazonaws.com - * @example https://bucket.s3.us-west-1.amazonaws.com/key - * @example https://bucket.s3.amazonaws.com/key - * @example https://china-bucket.s3.cn-north-1.amazonaws.com.cn/mykey + * + * - `https://only-bucket.s3.us-west-1.amazonaws.com` + * - `https://bucket.s3.us-west-1.amazonaws.com/key` + * - `https://bucket.s3.amazonaws.com/key` + * - `https://china-bucket.s3.cn-north-1.amazonaws.com.cn/mykey` * @param key The S3 key of the object. If not specified, the URL of the * bucket is returned. * @param options Options for generating URL. @@ -130,8 +132,8 @@ export interface IBucket extends IResource { /** * The S3 URL of an S3 object. For example: - * @example s3://onlybucket - * @example s3://bucket/key + * - `s3://onlybucket` + * - `s3://bucket/key` * @param key The S3 key of the object. If not specified, the S3 URL of the * bucket is returned. * @returns an ObjectS3Url token @@ -603,9 +605,11 @@ export abstract class BucketBase extends Resource implements IBucket { /** * The https URL of an S3 object. Specify `regional: false` at the options * for non-regional URLs. For example: - * @example https://s3.us-west-1.amazonaws.com/onlybucket - * @example https://s3.us-west-1.amazonaws.com/bucket/key - * @example https://s3.cn-north-1.amazonaws.com.cn/china-bucket/mykey + * + * - `https://s3.us-west-1.amazonaws.com/onlybucket` + * - `https://s3.us-west-1.amazonaws.com/bucket/key` + * - `https://s3.cn-north-1.amazonaws.com.cn/china-bucket/mykey` + * * @param key The S3 key of the object. If not specified, the URL of the * bucket is returned. * @returns an ObjectS3Url token @@ -622,10 +626,12 @@ export abstract class BucketBase extends Resource implements IBucket { /** * The virtual hosted-style URL of an S3 object. Specify `regional: false` at * the options for non-regional URL. For example: - * @example https://only-bucket.s3.us-west-1.amazonaws.com - * @example https://bucket.s3.us-west-1.amazonaws.com/key - * @example https://bucket.s3.amazonaws.com/key - * @example https://china-bucket.s3.cn-north-1.amazonaws.com.cn/mykey + * + * - `https://only-bucket.s3.us-west-1.amazonaws.com` + * - `https://bucket.s3.us-west-1.amazonaws.com/key` + * - `https://bucket.s3.amazonaws.com/key` + * - `https://china-bucket.s3.cn-north-1.amazonaws.com.cn/mykey` + * * @param key The S3 key of the object. If not specified, the URL of the * bucket is returned. * @param options Options for generating URL. @@ -642,8 +648,10 @@ export abstract class BucketBase extends Resource implements IBucket { /** * The S3 URL of an S3 object. For example: - * @example s3://onlybucket - * @example s3://bucket/key + * + * - `s3://onlybucket` + * - `s3://bucket/key` + * * @param key The S3 key of the object. If not specified, the S3 URL of the * bucket is returned. * @returns an ObjectS3Url token diff --git a/packages/@aws-cdk/aws-s3/package.json b/packages/@aws-cdk/aws-s3/package.json index e3feff8d0fe6c..f8153d202545d 100644 --- a/packages/@aws-cdk/aws-s3/package.json +++ b/packages/@aws-cdk/aws-s3/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-sns-subscriptions/package.json b/packages/@aws-cdk/aws-sns-subscriptions/package.json index ba1cfe852a8aa..6f8a4f5a2b9cc 100644 --- a/packages/@aws-cdk/aws-sns-subscriptions/package.json +++ b/packages/@aws-cdk/aws-sns-subscriptions/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-sns/package.json b/packages/@aws-cdk/aws-sns/package.json index 2250bcb72ba1b..b5f4039c63744 100644 --- a/packages/@aws-cdk/aws-sns/package.json +++ b/packages/@aws-cdk/aws-sns/package.json @@ -31,7 +31,14 @@ "excludeTypescript": [ "examples" ], - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-sqs/package.json b/packages/@aws-cdk/aws-sqs/package.json index 874d8caf10d72..af74b209b3931 100644 --- a/packages/@aws-cdk/aws-sqs/package.json +++ b/packages/@aws-cdk/aws-sqs/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-ssm/package.json b/packages/@aws-cdk/aws-ssm/package.json index 55ad40f1dfd04..cdf17bfb69c1c 100644 --- a/packages/@aws-cdk/aws-ssm/package.json +++ b/packages/@aws-cdk/aws-ssm/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts index 6a9eaab73eb4b..23e4079b77921 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts @@ -10,7 +10,7 @@ export interface AthenaGetQueryExecutionProps extends sfn.TaskStateBaseProps { /** * Query that will be retrieved * - * @example 'adfsaf-23trf23-f23rt23' + * Example value: `adfsaf-23trf23-f23rt23` */ readonly queryExecutionId: string; } diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts index 07ec38efa97e1..700b43fc2a599 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts @@ -10,8 +10,8 @@ export interface AthenaGetQueryResultsProps extends sfn.TaskStateBaseProps { /** * Query that will be retrieved * - * @example 'adfsaf-23trf23-f23rt23' - */ + * Example value: `adfsaf-23trf23-f23rt23` + */ readonly queryExecutionId: string; /** diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts index f23bd66fc5591..ba3f68b95abb1 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts @@ -212,8 +212,9 @@ export interface ResultConfiguration { /** * S3 path of query results * + * Example value: `s3://query-results-bucket/folder/` + * * @default - Query Result Location set in Athena settings for this workgroup - * @example s3://query-results-bucket/folder/ */ readonly outputLocation?: s3.Location; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts index 0921cf3b2521a..bed1b16a86f70 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts @@ -119,10 +119,10 @@ export class DynamoProjectionExpression { export class DynamoAttributeValue { /** * Sets an attribute of type String. For example: "S": "Hello" - * Strings may be literal values or as JsonPath. + * Strings may be literal values or as JsonPath. Example values: * - * @example `DynamoAttributeValue.fromString('someValue') - * @example `DynamoAttributeValue.fromString(JsonPath.stringAt('$.bar')) + * - `DynamoAttributeValue.fromString('someValue')` + * - `DynamoAttributeValue.fromString(JsonPath.stringAt('$.bar'))` */ public static fromString(value: string) { return new DynamoAttributeValue({ S: value }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts index 7fb010119373b..5b90ce066c70d 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts @@ -12,7 +12,7 @@ export interface EvaluateExpressionProps extends sfn.TaskStateBaseProps { /** * The expression to evaluate. The expression may contain state paths. * - * @example '$.a + $.b' + * Example value: `'$.a + $.b'` */ readonly expression: string; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts index 457bdfa6d0011..2c08c1ac41966 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts @@ -16,9 +16,10 @@ export interface EventBridgePutEventsEntry { * * Can either be provided as an object or as a JSON-serialized string * @example - * sfn.TaskInput.fromText('{"instance-id": "i-1234567890abcdef0", "state": "terminated"}') - * sfn.TaskInput.fromObject({ Message: 'Hello from Step Functions' }) - * sfn.TaskInput.fromJsonPathAt('$.EventDetail') + * + * sfn.TaskInput.fromText('{"instance-id": "i-1234567890abcdef0", "state": "terminated"}'); + * sfn.TaskInput.fromObject({ Message: 'Hello from Step Functions' }); + * sfn.TaskInput.fromJsonPathAt('$.EventDetail'); */ readonly detail: sfn.TaskInput; @@ -40,7 +41,8 @@ export interface EventBridgePutEventsEntry { /** * The service or application that caused this event to be generated * - * @example 'com.example.service' + * Example value: `com.example.service` + * * @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html */ readonly source: string; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/package.json b/packages/@aws-cdk/aws-stepfunctions-tasks/package.json index 2ff381bd3f9d0..daa88936b437c 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/package.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts index 8386b3ce334b1..f0fd18d22c090 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts @@ -18,21 +18,21 @@ export class WaitTime { /** * Wait until the given ISO8601 timestamp * - * @example 2016-03-14T01:59:00Z + * Example value: `2016-03-14T01:59:00Z` */ public static timestamp(timestamp: string) { return new WaitTime({ Timestamp: timestamp }); } /** * Wait for a number of seconds stored in the state object. * - * @example $.waitSeconds + * Example value: `$.waitSeconds` */ public static secondsPath(path: string) { return new WaitTime({ SecondsPath: path }); } /** * Wait until a timestamp found in the state object. * - * @example $.waitTimestamp + * Example value: `$.waitTimestamp` */ public static timestampPath(path: string) { return new WaitTime({ TimestampPath: path }); } diff --git a/packages/@aws-cdk/aws-stepfunctions/package.json b/packages/@aws-cdk/aws-stepfunctions/package.json index 701d06a238562..40cea293bc09f 100644 --- a/packages/@aws-cdk/aws-stepfunctions/package.json +++ b/packages/@aws-cdk/aws-stepfunctions/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/aws-synthetics/package.json b/packages/@aws-cdk/aws-synthetics/package.json index 76e2fa4520b1e..745f97fc21261 100644 --- a/packages/@aws-cdk/aws-synthetics/package.json +++ b/packages/@aws-cdk/aws-synthetics/package.json @@ -28,7 +28,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "repository": { "type": "git", diff --git a/packages/@aws-cdk/pipelines/lib/blueprint/stack-deployment.ts b/packages/@aws-cdk/pipelines/lib/blueprint/stack-deployment.ts index 488551f4eefb7..b3e88cbfe026e 100644 --- a/packages/@aws-cdk/pipelines/lib/blueprint/stack-deployment.ts +++ b/packages/@aws-cdk/pipelines/lib/blueprint/stack-deployment.ts @@ -183,7 +183,7 @@ export class StackDeployment { * This is `undefined` if the stack template is not published. Use the * `DefaultStackSynthesizer` to ensure it is. * - * @example https://bucket.s3.amazonaws.com/object/key + * Example value: `https://bucket.s3.amazonaws.com/object/key` */ public readonly templateUrl?: string; diff --git a/packages/@aws-cdk/pipelines/package.json b/packages/@aws-cdk/pipelines/package.json index b3d838723ed75..ec3538c30b4c9 100644 --- a/packages/@aws-cdk/pipelines/package.json +++ b/packages/@aws-cdk/pipelines/package.json @@ -126,7 +126,14 @@ ] } }, - "projectReferences": true + "projectReferences": true, + "metadata": { + "jsii": { + "rosetta": { + "strict": true + } + } + } }, "awscdkio": { "announce": false From 69372962ee79c75ff5ff9cdd15026563d79fcb33 Mon Sep 17 00:00:00 2001 From: Tatsuya Yamamoto Date: Wed, 10 Nov 2021 04:51:26 +0900 Subject: [PATCH 5/8] chore(iot-actions): simplify cloudwatch-logs-action test (#17385) This PR refactor the test that I committed earlier based on the above comment. - https://github.com/aws/aws-cdk/pull/17307#discussion_r742181458 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../cloudwatch-logs-action.test.ts | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/packages/@aws-cdk/aws-iot-actions/test/cloudwatch-logs/cloudwatch-logs-action.test.ts b/packages/@aws-cdk/aws-iot-actions/test/cloudwatch-logs/cloudwatch-logs-action.test.ts index 4e25f43367c31..3b6ecd2d57fbc 100644 --- a/packages/@aws-cdk/aws-iot-actions/test/cloudwatch-logs/cloudwatch-logs-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions/test/cloudwatch-logs/cloudwatch-logs-action.test.ts @@ -11,7 +11,7 @@ test('Default cloudwatch logs action', () => { const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); - const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); + const logGroup = logs.LogGroup.fromLogGroupArn(stack, 'my-log-group', 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group'); // WHEN topicRule.addAction( @@ -24,7 +24,7 @@ test('Default cloudwatch logs action', () => { Actions: [ { CloudwatchLogs: { - LogGroupName: { Ref: 'MyLogGroup5C0DAD85' }, + LogGroupName: 'my-log-group', RoleArn: { 'Fn::GetAtt': [ 'MyTopicRuleTopicRuleActionRoleCE2D05DA', @@ -58,16 +58,12 @@ test('Default cloudwatch logs action', () => { { Action: ['logs:CreateLogStream', 'logs:PutLogEvents'], Effect: 'Allow', - Resource: { - 'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn'], - }, + Resource: 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:*', }, { Action: 'logs:DescribeLogStreams', Effect: 'Allow', - Resource: { - 'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn'], - }, + Resource: 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:*', }, ], Version: '2012-10-17', @@ -85,7 +81,7 @@ test('can set role', () => { const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); - const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); + const logGroup = logs.LogGroup.fromLogGroupArn(stack, 'my-log-group', 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group'); const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); // WHEN @@ -101,48 +97,26 @@ test('can set role', () => { Actions: [ { CloudwatchLogs: { - LogGroupName: { Ref: 'MyLogGroup5C0DAD85' }, + LogGroupName: 'my-log-group', RoleArn: 'arn:aws:iam::123456789012:role/ForTest', }, }, ], }, }); -}); - -test('The specified role is added a policy needed for sending data to logs', () => { - // GIVEN - const stack = new cdk.Stack(); - const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { - sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), - }); - const logGroup = new logs.LogGroup(stack, 'MyLogGroup'); - const role = iam.Role.fromRoleArn(stack, 'MyRole', 'arn:aws:iam::123456789012:role/ForTest'); - - // WHEN - topicRule.addAction( - new actions.CloudWatchLogsAction(logGroup, { - role, - }), - ); - // THEN Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { Action: ['logs:CreateLogStream', 'logs:PutLogEvents'], Effect: 'Allow', - Resource: { - 'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn'], - }, + Resource: 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:*', }, { Action: 'logs:DescribeLogStreams', Effect: 'Allow', - Resource: { - 'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn'], - }, + Resource: 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group:*', }, ], Version: '2012-10-17', @@ -152,16 +126,14 @@ test('The specified role is added a policy needed for sending data to logs', () }); }); - test('When multiple actions are omitted role property, the actions use same one role', () => { - // GIVEN // GIVEN const stack = new cdk.Stack(); const topicRule = new iot.TopicRule(stack, 'MyTopicRule', { sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); - const logGroup1 = new logs.LogGroup(stack, 'MyLogGroup1'); - const logGroup2 = new logs.LogGroup(stack, 'MyLogGroup2'); + const logGroup1 = logs.LogGroup.fromLogGroupArn(stack, 'my-log-group1', 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group1'); + const logGroup2 = logs.LogGroup.fromLogGroupArn(stack, 'my-log-group2', 'arn:aws:logs:us-east-1:123456789012:log-group:my-log-group2'); // WHEN topicRule.addAction(new actions.CloudWatchLogsAction(logGroup1)); @@ -173,7 +145,7 @@ test('When multiple actions are omitted role property, the actions use same one Actions: [ { CloudwatchLogs: { - LogGroupName: { Ref: 'MyLogGroup14A6E382A' }, + LogGroupName: 'my-log-group1', RoleArn: { 'Fn::GetAtt': [ 'MyTopicRuleTopicRuleActionRoleCE2D05DA', @@ -184,7 +156,7 @@ test('When multiple actions are omitted role property, the actions use same one }, { CloudwatchLogs: { - LogGroupName: { Ref: 'MyLogGroup279D6359D' }, + LogGroupName: 'my-log-group2', RoleArn: { 'Fn::GetAtt': [ 'MyTopicRuleTopicRuleActionRoleCE2D05DA', From a39146840a10472c8afee71bf1a1cfc3cacb5f72 Mon Sep 17 00:00:00 2001 From: Ryan Parker Date: Tue, 9 Nov 2021 12:30:07 -0800 Subject: [PATCH 6/8] fix(aws-logs): include new `policy.ts` exports in `index.ts` exports (#17403) ## Summary This PR modifies the aws-logs `index.ts` file to also forward the exports from `policy.ts` ([a newly created file](https://github.com/aws/aws-cdk/pull/17015) that implements the `ResourcePolicy` class). Fixes: https://github.com/aws/aws-cdk/issues/17402 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-logs/lib/index.ts | 1 + packages/@aws-cdk/aws-logs/lib/policy.ts | 12 +++-- .../@aws-cdk/aws-logs/test/policy.test.ts | 52 +++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 packages/@aws-cdk/aws-logs/test/policy.test.ts diff --git a/packages/@aws-cdk/aws-logs/lib/index.ts b/packages/@aws-cdk/aws-logs/lib/index.ts index 5054715ffe52b..416a9c9a9b257 100644 --- a/packages/@aws-cdk/aws-logs/lib/index.ts +++ b/packages/@aws-cdk/aws-logs/lib/index.ts @@ -5,6 +5,7 @@ export * from './metric-filter'; export * from './pattern'; export * from './subscription-filter'; export * from './log-retention'; +export * from './policy'; // AWS::Logs CloudFormation Resources: export * from './logs.generated'; diff --git a/packages/@aws-cdk/aws-logs/lib/policy.ts b/packages/@aws-cdk/aws-logs/lib/policy.ts index 974f517d48b25..de3af44f1ae2f 100644 --- a/packages/@aws-cdk/aws-logs/lib/policy.ts +++ b/packages/@aws-cdk/aws-logs/lib/policy.ts @@ -11,7 +11,7 @@ export interface ResourcePolicyProps { * Name of the log group resource policy * @default - Uses a unique id based on the construct path */ - readonly policyName?: string; + readonly resourcePolicyName?: string; /** * Initial statements to add to the resource policy @@ -31,15 +31,19 @@ export class ResourcePolicy extends Resource { public readonly document = new PolicyDocument(); constructor(scope: Construct, id: string, props?: ResourcePolicyProps) { - super(scope, id); - new CfnResourcePolicy(this, 'Resource', { + super(scope, id, { + physicalName: props?.resourcePolicyName, + }); + + new CfnResourcePolicy(this, 'ResourcePolicy', { policyName: Lazy.string({ - produce: () => props?.policyName ?? Names.uniqueId(this), + produce: () => props?.resourcePolicyName ?? Names.uniqueId(this), }), policyDocument: Lazy.string({ produce: () => JSON.stringify(this.document), }), }); + if (props?.policyStatements) { this.document.addStatements(...props.policyStatements); } diff --git a/packages/@aws-cdk/aws-logs/test/policy.test.ts b/packages/@aws-cdk/aws-logs/test/policy.test.ts new file mode 100644 index 0000000000000..4b2684a9957b1 --- /dev/null +++ b/packages/@aws-cdk/aws-logs/test/policy.test.ts @@ -0,0 +1,52 @@ +import '@aws-cdk/assert-internal/jest'; +import { PolicyStatement, ServicePrincipal } from '@aws-cdk/aws-iam'; +import { Stack } from '@aws-cdk/core'; +import { LogGroup, ResourcePolicy } from '../lib'; + +describe('resource policy', () => { + test('ResourcePolicy is added to stack, when .addToResourcePolicy() is provided a valid Statement', () => { + // GIVEN + const stack = new Stack(); + const logGroup = new LogGroup(stack, 'LogGroup'); + + // WHEN + logGroup.addToResourcePolicy(new PolicyStatement({ + actions: ['logs:CreateLogStream'], + resources: ['*'], + })); + + // THEN + expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + PolicyName: 'LogGroupPolicy643B329C', + PolicyDocument: JSON.stringify({ + Statement: [ + { + Action: 'logs:CreateLogStream', + Effect: 'Allow', + Resource: '*', + }, + ], + Version: '2012-10-17', + }), + }); + }); + + test('ResourcePolicy is added to stack, when created manually/directly', () => { + // GIVEN + const stack = new Stack(); + const logGroup = new LogGroup(stack, 'LogGroup'); + + // WHEN + const resourcePolicy = new ResourcePolicy(stack, 'ResourcePolicy'); + resourcePolicy.document.addStatements(new PolicyStatement({ + actions: ['logs:CreateLogStream', 'logs:PutLogEvents'], + principals: [new ServicePrincipal('es.amazonaws.com')], + resources: [logGroup.logGroupArn], + })); + + // THEN + expect(stack).toHaveResource('AWS::Logs::ResourcePolicy', { + PolicyName: 'ResourcePolicy', + }); + }); +}); From ec5b102e560e241b21c63773817114fc44f7898a Mon Sep 17 00:00:00 2001 From: Ryan Parker Date: Tue, 9 Nov 2021 13:10:16 -0800 Subject: [PATCH 7/8] feat(lambda): singleton function: access runtime, log group and configure layers and environment (#17372) ## Summary This PR adds the following to `SingletonFunction`: - `runtime` - property - `logGroup` - property - `addLayers()` - method - `addEnvironment()` - method Fixes: https://github.com/aws/aws-cdk/issues/17369 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-lambda/lib/singleton-lambda.ts | 48 +++++++++- .../aws-lambda/test/singleton-lambda.test.ts | 87 +++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts index 431b9bf6a71d9..c096730b1e8eb 100644 --- a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts @@ -1,11 +1,14 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; +import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { Function as LambdaFunction, FunctionProps } from './function'; +import { Function as LambdaFunction, FunctionProps, EnvironmentOptions } from './function'; import { FunctionBase } from './function-base'; import { Version } from './lambda-version'; +import { ILayerVersion } from './layers'; import { Permission } from './permission'; +import { Runtime } from './runtime'; /** * Properties for a newly created singleton Lambda @@ -47,6 +50,12 @@ export class SingletonFunction extends FunctionBase { public readonly functionArn: string; public readonly role?: iam.IRole; public readonly permissionsNode: cdk.ConstructNode; + + /** + * The runtime environment for the Lambda function. + */ + public readonly runtime: Runtime; + protected readonly canCreatePermissions: boolean; private lambdaFunction: LambdaFunction; @@ -59,6 +68,7 @@ export class SingletonFunction extends FunctionBase { this.functionArn = this.lambdaFunction.functionArn; this.functionName = this.lambdaFunction.functionName; this.role = this.lambdaFunction.role; + this.runtime = this.lambdaFunction.runtime; this.grantPrincipal = this.lambdaFunction.grantPrincipal; this.canCreatePermissions = true; // Doesn't matter, addPermission is overriden anyway @@ -78,6 +88,20 @@ export class SingletonFunction extends FunctionBase { return this.lambdaFunction.connections; } + /** + * The LogGroup where the Lambda function's logs are made available. + * + * If either `logRetention` is set or this property is called, a CloudFormation custom resource is added to the stack that + * pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention + * period (never expire, by default). + * + * Further, if the log group already exists and the `logRetention` is not set, the custom resource will reset the log retention + * to never expire even if it was configured with a different value. + */ + public get logGroup(): logs.ILogGroup { + return this.lambdaFunction.logGroup; + } + /** * Returns a `lambda.Version` which represents the current version of this * singleton Lambda function. A new version will be created every time the @@ -90,6 +114,28 @@ export class SingletonFunction extends FunctionBase { return this.lambdaFunction.currentVersion; } + /** + * Adds an environment variable to this Lambda function. + * If this is a ref to a Lambda function, this operation results in a no-op. + * @param key The environment variable key. + * @param value The environment variable's value. + * @param options Environment variable options. + */ + public addEnvironment(key: string, value: string, options?: EnvironmentOptions) { + return this.lambdaFunction.addEnvironment(key, value, options); + } + + /** + * Adds one or more Lambda Layers to this Lambda function. + * + * @param layers the layers to be added. + * + * @throws if there are already 5 layers on this function, or the layer is incompatible with this function's runtime. + */ + public addLayers(...layers: ILayerVersion[]) { + return this.lambdaFunction.addLayers(...layers); + } + public addPermission(name: string, permission: Permission) { return this.lambdaFunction.addPermission(name, permission); } diff --git a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts index 3bf78253d5ed6..4200b7a18a6e5 100644 --- a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts @@ -2,6 +2,7 @@ import '@aws-cdk/assert-internal/jest'; import { ResourcePart } from '@aws-cdk/assert-internal'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; +import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import * as lambda from '../lib'; @@ -109,6 +110,57 @@ describe('singleton lambda', () => { }, ResourcePart.CompleteDefinition); }); + test('Environment is added to Lambda, when .addEnvironment() is provided one key pair', () => { + // GIVEN + const stack = new cdk.Stack(); + const singleton = new lambda.SingletonFunction(stack, 'Singleton', { + uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.PYTHON_2_7, + handler: 'index.hello', + timeout: cdk.Duration.minutes(5), + }); + + // WHEN + singleton.addEnvironment('KEY', 'value'); + + // THEN + expect(stack).toHaveResource('AWS::Lambda::Function', { + Environment: { + Variables: { + KEY: 'value', + }, + }, + }); + }); + + test('Layer is added to Lambda, when .addLayers() is provided a valid layer', () => { + // GIVEN + const stack = new cdk.Stack(); + const singleton = new lambda.SingletonFunction(stack, 'Singleton', { + uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.PYTHON_2_7, + handler: 'index.hello', + timeout: cdk.Duration.minutes(5), + }); + const bucket = new s3.Bucket(stack, 'Bucket'); + const layer = new lambda.LayerVersion(stack, 'myLayer', { + code: new lambda.S3Code(bucket, 'ObjectKey'), + compatibleRuntimes: [lambda.Runtime.PYTHON_2_7], + }); + + // WHEN + singleton.addLayers(layer); + + // THEN + expect(stack).toHaveResource('AWS::Lambda::Function', { + Layers: [{ + Ref: 'myLayerBA1B098A', + }], + }); + }); + test('grantInvoke works correctly', () => { // GIVEN const stack = new cdk.Stack(); @@ -154,6 +206,41 @@ describe('singleton lambda', () => { .toThrow(/contains environment variables .* and is not compatible with Lambda@Edge/); }); + test('logGroup is correctly returned', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const singleton = new lambda.SingletonFunction(stack, 'Singleton', { + uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.PYTHON_2_7, + handler: 'index.hello', + timeout: cdk.Duration.minutes(5), + }); + + // THEN + expect(singleton.logGroup.logGroupName).toBeDefined(); + expect(singleton.logGroup.logGroupArn).toBeDefined(); + }); + + test('runtime is correctly returned', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const singleton = new lambda.SingletonFunction(stack, 'Singleton', { + uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.PYTHON_2_7, + handler: 'index.hello', + timeout: cdk.Duration.minutes(5), + }); + + // THEN + expect(singleton.runtime).toStrictEqual(lambda.Runtime.PYTHON_2_7); + }); + test('current version of a singleton function', () => { // GIVEN const stack = new cdk.Stack(); From 9c77e941252ad16a2744577b6333ee5054302a30 Mon Sep 17 00:00:00 2001 From: Ryan Parker Date: Tue, 9 Nov 2021 13:49:17 -0800 Subject: [PATCH 8/8] fix(aws-codebuild): add @aws-cdk/asserts to package deps (#17435) ## Summary This PR adds `@aws-cdk/asserts` to the dependency list of `aws-codebuild`. Fixes: https://github.com/aws/aws-cdk/issues/17416 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-codebuild/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-codebuild/package.json b/packages/@aws-cdk/aws-codebuild/package.json index 05c5e55339acb..3d1609d9665b4 100644 --- a/packages/@aws-cdk/aws-codebuild/package.json +++ b/packages/@aws-cdk/aws-codebuild/package.json @@ -95,6 +95,7 @@ "jest": "^27.3.1" }, "dependencies": { + "@aws-cdk/assets": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-codecommit": "0.0.0", "@aws-cdk/aws-codestarnotifications": "0.0.0",