diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.assets.json new file mode 100644 index 0000000000000..2bc396778e5f5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "48.0.0", + "files": { + "cd9c63111d91fd1b2f1428793fbb64374db7c9eddb53b1a96feea5933be52faa": { + "displayName": "add-to-resource-policy-test-stack Template", + "source": { + "path": "add-to-resource-policy-test-stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region-7305eab0": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "cd9c63111d91fd1b2f1428793fbb64374db7c9eddb53b1a96feea5933be52faa.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.template.json new file mode 100644 index 0000000000000..c2d0dca2fe67a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/add-to-resource-policy-test-stack.template.json @@ -0,0 +1,154 @@ +{ + "Resources": { + "WildcardTableE075CD4D": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, + "ResourcePolicy": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:GetItem", + "dynamodb:PutItem", + "dynamodb:Query" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": "*" + } + ], + "Version": "2012-10-17" + } + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "ScopedTableC019D4A1": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, + "ResourcePolicy": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:GetItem", + "dynamodb:Query" + ], + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::", + { + "Ref": "AWS::AccountId" + }, + ":root" + ] + ] + } + }, + "Resource": { + "Fn::Sub": "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-scoped-table" + } + } + ], + "Version": "2012-10-17" + } + }, + "TableName": "my-explicit-scoped-table" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets.json new file mode 100644 index 0000000000000..808b1c384aa08 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets.json @@ -0,0 +1,20 @@ +{ + "version": "48.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "displayName": "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA Template", + "source": { + "path": "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region-d8d86b35": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/cdk.out new file mode 100644 index 0000000000000..523a9aac37cbf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"48.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/integ.json new file mode 100644 index 0000000000000..86aa781f5205e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "48.0.0", + "testCases": { + "add-to-resource-policy-integ-test/DefaultTest": { + "stacks": [ + "add-to-resource-policy-test-stack" + ], + "assertionStack": "add-to-resource-policy-integ-test/DefaultTest/DeployAssert", + "assertionStackName": "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA" + } + }, + "minimumCliVersion": "2.1027.0" +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/manifest.json new file mode 100644 index 0000000000000..bf4d7523521bf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/manifest.json @@ -0,0 +1,650 @@ +{ + "version": "48.0.0", + "artifacts": { + "add-to-resource-policy-test-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "add-to-resource-policy-test-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "add-to-resource-policy-test-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "add-to-resource-policy-test-stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cd9c63111d91fd1b2f1428793fbb64374db7c9eddb53b1a96feea5933be52faa.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "add-to-resource-policy-test-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "add-to-resource-policy-test-stack.assets" + ], + "metadata": { + "/add-to-resource-policy-test-stack/WildcardTable": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "partitionKey": { + "name": "*", + "type": "S" + }, + "removalPolicy": "destroy" + } + } + ], + "/add-to-resource-policy-test-stack/WildcardTable/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WildcardTableE075CD4D" + } + ], + "/add-to-resource-policy-test-stack/WildcardTable/ScalingRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/add-to-resource-policy-test-stack/ScopedTable": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "tableName": "*", + "partitionKey": { + "name": "*", + "type": "S" + }, + "removalPolicy": "destroy" + } + }, + { + "type": "aws:cdk:hasPhysicalName", + "data": { + "Ref": "ScopedTableC019D4A1" + } + } + ], + "/add-to-resource-policy-test-stack/ScopedTable/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ScopedTableC019D4A1" + } + ], + "/add-to-resource-policy-test-stack/ScopedTable/ScalingRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/add-to-resource-policy-test-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/add-to-resource-policy-test-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ], + "TestTable5769773A": [ + { + "type": "aws:cdk:logicalId", + "data": "TestTable5769773A", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } + ] + }, + "displayName": "add-to-resource-policy-test-stack" + }, + "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "addtoresourcepolicyintegtestDefaultTestDeployAssert0D97EAEA.assets" + ], + "metadata": { + "/add-to-resource-policy-integ-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/add-to-resource-policy-integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "add-to-resource-policy-integ-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "aws-cdk-lib/feature-flag-report": { + "type": "cdk:feature-flag-report", + "properties": { + "module": "aws-cdk-lib", + "flags": { + "@aws-cdk/aws-signer:signingProfileNamePassedToCfn": { + "recommendedValue": true, + "explanation": "Pass signingProfileName to CfnSigningProfile" + }, + "@aws-cdk/core:newStyleStackSynthesis": { + "recommendedValue": true, + "explanation": "Switch to new stack synthesis method which enables CI/CD", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:stackRelativeExports": { + "recommendedValue": true, + "explanation": "Name exports based on the construct paths relative to the stack, rather than the global construct path", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": { + "recommendedValue": true, + "explanation": "Disable implicit openListener when custom security groups are provided" + }, + "@aws-cdk/aws-rds:lowercaseDbIdentifier": { + "recommendedValue": true, + "explanation": "Force lowercasing of RDS Cluster names in CDK", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": { + "recommendedValue": true, + "explanation": "Allow adding/removing multiple UsagePlanKeys independently", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeVersionProps": { + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeLayerVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`." + }, + "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": { + "recommendedValue": true, + "explanation": "Enable this feature flag to have cloudfront distributions use the security policy TLSv1.2_2021 by default.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:checkSecretUsage": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this flag to make it impossible to accidentally use SecretValues in unsafe locations" + }, + "@aws-cdk/core:target-partitions": { + "recommendedValue": [ + "aws", + "aws-cn" + ], + "explanation": "What regions to include in lookup tables of environment agnostic stacks" + }, + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": { + "userValue": true, + "recommendedValue": true, + "explanation": "ECS extensions will automatically add an `awslogs` driver if no logging is specified" + }, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to have Launch Templates generated by the `InstanceRequireImdsv2Aspect` use unique names." + }, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": { + "userValue": true, + "recommendedValue": true, + "explanation": "ARN format used by ECS. In the new ARN format, the cluster name is part of the resource ID." + }, + "@aws-cdk/aws-iam:minimizePolicies": { + "userValue": true, + "recommendedValue": true, + "explanation": "Minimize IAM policies by combining Statements" + }, + "@aws-cdk/core:validateSnapshotRemovalPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Error on snapshot removal policies on resources that do not support it." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate key aliases that include the stack name" + }, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to create an S3 bucket policy by default in cases where an AWS service would automatically create the Policy if one does not exist." + }, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict KMS key policy for encrypted Queues a bit more" + }, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make default CloudWatch Role behavior safe for multiple API Gateways in one environment" + }, + "@aws-cdk/core:enablePartitionLiterals": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make ARNs concrete if AWS partition is known" + }, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": { + "userValue": true, + "recommendedValue": true, + "explanation": "Event Rules may only push to encrypted SQS queues in the same account" + }, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": { + "userValue": true, + "recommendedValue": true, + "explanation": "Avoid setting the \"ECS\" deployment controller when adding a circuit breaker" + }, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature to by default create default policy names for imported roles that depend on the stack the role is in." + }, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use S3 Bucket Policy instead of ACLs for Server Access Logging" + }, + "@aws-cdk/aws-route53-patters:useCertificate": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use the official `Certificate` resource instead of `DnsValidatedCertificate`" + }, + "@aws-cdk/customresources:installLatestAwsSdkDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "Whether to install the latest SDK by default in AwsCustomResource" + }, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use unique resource name for Database Proxy" + }, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Remove CloudWatch alarms from deployment group" + }, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include authorizer configuration in the calculation of the API deployment logical ID." + }, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": { + "userValue": true, + "recommendedValue": true, + "explanation": "Define user data for a launch template by default when a machine image is provided." + }, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": { + "userValue": true, + "recommendedValue": true, + "explanation": "SecretTargetAttachments uses the ResourcePolicy of the attached Secret." + }, + "@aws-cdk/aws-redshift:columnId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Whether to use an ID to track Redshift column changes" + }, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable AmazonEMRServicePolicy_v2 managed policies" + }, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict access to the VPC default security group" + }, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a unique id for each RequestValidator added to a method" + }, + "@aws-cdk/aws-kms:aliasNameRef": { + "userValue": true, + "recommendedValue": true, + "explanation": "KMS Alias name and keyArn will have implicit reference to KMS Key" + }, + "@aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable grant methods on Aliases imported by name to use kms:ResourceAliases condition" + }, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a launch template when creating an AutoScalingGroup" + }, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include the stack prefix in the stack name generation process" + }, + "@aws-cdk/aws-efs:denyAnonymousAccess": { + "userValue": true, + "recommendedValue": true, + "explanation": "EFS denies anonymous clients accesses" + }, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables support for Multi-AZ with Standby deployment for opensearch domains" + }, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables aws-lambda-nodejs.Function to use the latest available NodeJs runtime as the default" + }, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, mount targets will have a stable logicalId that is linked to the associated subnet." + }, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change." + }, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, will always use the arn for identifiers for CfnSourceApiAssociation in the GraphqlApi construct rather than id." + }, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials." + }, + "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the CodeCommit source action is using the default branch name 'main'." + }, + "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default value for crossAccountKeys to false." + }, + "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default pipeline type to V2." + }, + "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, IAM Policy created from KMS key grant will reduce the resource scope to this key only." + }, + "@aws-cdk/pipelines:reduceAssetRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from PipelineAssetsFileRole trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-eks:nodegroupNameAttribute": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, nodegroupName attribute of the provisioned EKS NodeGroup will not have the cluster name prefix." + }, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default volume type of the EBS volume will be GP3" + }, + "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, remove default deployment alarm settings" + }, + "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, the custom resource used for `AwsCustomResource` will configure the `logApiResponseData` property as true by default" + }, + "@aws-cdk/aws-s3:keepNotificationInImportedBucket": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, Adding notifications to a bucket in the current stack will not remove notification from imported stack." + }, + "@aws-cdk/aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask": { + "recommendedValue": true, + "explanation": "When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:explicitStackTags": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, stack tags need to be assigned explicitly on a Stack." + }, + "@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": { + "userValue": false, + "recommendedValue": false, + "explanation": "When set to true along with canContainersAccessInstanceRole=false in ECS cluster, new updated commands will be added to UserData to block container accessing IMDS. **Applicable to Linux only. IMPORTANT: See [details.](#aws-cdkaws-ecsenableImdsBlockingDeprecatedFeature)**" + }, + "@aws-cdk/aws-ecs:disableEcsImdsBlocking": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, CDK synth will throw exception if canContainersAccessInstanceRole is false. **IMPORTANT: See [details.](#aws-cdkaws-ecsdisableEcsImdsBlocking)**" + }, + "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, we will only grant the necessary permissions when users specify cloudwatch log group through logConfiguration" + }, + "@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled will allow you to specify a resource policy per replica, and not copy the source table policy to all replicas" + }, + "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, initOptions.timeout and resourceSignalTimeout values will be summed together." + }, + "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a Lambda authorizer Permission created when using GraphqlApi will be properly scoped with a SourceArn." + }, + "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn`" + }, + "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CFN templates added with `cfn-include` will error if the template contains Resource Update or Create policies with CFN Intrinsics that include non-primitive values." + }, + "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, both `@aws-sdk` and `@smithy` packages will be excluded from the Lambda Node.js 18.x runtime to prevent version mismatches in bundled applications." + }, + "@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resource of IAM Run Ecs policy generated by SFN EcsRunTask will reference the definition, instead of constructing ARN." + }, + "@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the BastionHost construct will use the latest Amazon Linux 2023 AMI, instead of Amazon Linux 2." + }, + "@aws-cdk/core:aspectStabilization": { + "recommendedValue": true, + "explanation": "When enabled, a stabilization loop will be run when invoking Aspects during synthesis.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, use a new method for DNS Name of user pool domain target without creating a custom resource." + }, + "@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default security group ingress rules will allow IPv6 ingress from anywhere" + }, + "@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default behaviour of OIDC provider will reject unauthorized connections" + }, + "@aws-cdk/core:enableAdditionalMetadataCollection": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will expand the scope of usage data collected to better inform CDK development and improve communication for security concerns and emerging issues." + }, + "@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": { + "userValue": false, + "recommendedValue": false, + "explanation": "[Deprecated] When enabled, Lambda will create new inline policies with AddToRolePolicy instead of adding to the Default Policy Statement" + }, + "@aws-cdk/aws-s3:setUniqueReplicationRoleName": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will automatically generate a unique role name that is used for s3 object replication." + }, + "@aws-cdk/pipelines:reduceStageRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from Stage addActions trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-events:requireEventBusPolicySid": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, grantPutEventsTo() will use resource policies with Statement IDs for service principals." + }, + "@aws-cdk/core:aspectPrioritiesMutating": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, Aspects added by the construct library on your behalf will be given a priority of MUTATING." + }, + "@aws-cdk/aws-dynamodb:retainTableReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, table replica will be default to the removal policy of source table unless specified otherwise." + }, + "@aws-cdk/cognito:logUserPoolClientSecretValue": { + "recommendedValue": false, + "explanation": "When disabled, the value of the user pool client secret will not be logged in the custom resource lambda function logs." + }, + "@aws-cdk/pipelines:reduceCrossAccountActionRoleTrustScope": { + "recommendedValue": true, + "explanation": "When enabled, scopes down the trust policy for the cross-account action role", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resultWriterV2 property of DistributedMap will be used insted of resultWriter" + }, + "@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": { + "userValue": true, + "recommendedValue": true, + "explanation": "Add an S3 trust policy to a KMS key resource policy for SNS subscriptions." + }, + "@aws-cdk/aws-ec2:requirePrivateSubnetsForEgressOnlyInternetGateway": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the EgressOnlyGateway resource is only created if private subnets are defined in the dual-stack VPC." + }, + "@aws-cdk/aws-ec2-alpha:useResourceIdForVpcV2Migration": { + "recommendedValue": false, + "explanation": "When enabled, use resource IDs for VPC V2 migration" + }, + "@aws-cdk/aws-s3:publicAccessBlockedByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, setting any combination of options for BlockPublicAccess will automatically set true for any options not defined." + }, + "@aws-cdk/aws-lambda:useCdkManagedLogGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK creates and manages loggroup for the lambda function" + } + } + } + } + }, + "minimumCliVersion": "2.1027.0" +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/tree.json new file mode 100644 index 0000000000000..ba9528f772719 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.js.snapshot/tree.json @@ -0,0 +1 @@ +{"version":"tree-0.1","tree":{"id":"App","path":"","constructInfo":{"fqn":"aws-cdk-lib.App","version":"0.0.0"},"children":{"add-to-resource-policy-test-stack":{"id":"add-to-resource-policy-test-stack","path":"add-to-resource-policy-test-stack","constructInfo":{"fqn":"aws-cdk-lib.Stack","version":"0.0.0"},"children":{"WildcardTable":{"id":"WildcardTable","path":"add-to-resource-policy-test-stack/WildcardTable","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.Table","version":"0.0.0","metadata":[{"partitionKey":{"name":"*","type":"S"},"removalPolicy":"destroy"}]},"children":{"Resource":{"id":"Resource","path":"add-to-resource-policy-test-stack/WildcardTable/Resource","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.CfnTable","version":"0.0.0"},"attributes":{"aws:cdk:cloudformation:type":"AWS::DynamoDB::Table","aws:cdk:cloudformation:props":{"attributeDefinitions":[{"attributeName":"id","attributeType":"S"}],"keySchema":[{"attributeName":"id","keyType":"HASH"}],"provisionedThroughput":{"readCapacityUnits":5,"writeCapacityUnits":5},"resourcePolicy":{"policyDocument":{"Statement":[{"Action":["dynamodb:GetItem","dynamodb:PutItem","dynamodb:Query"],"Effect":"Allow","Principal":{"AWS":{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":iam::",{"Ref":"AWS::AccountId"},":root"]]}},"Resource":"*"}],"Version":"2012-10-17"}}}}},"ScalingRole":{"id":"ScalingRole","path":"add-to-resource-policy-test-stack/WildcardTable/ScalingRole","constructInfo":{"fqn":"aws-cdk-lib.Resource","version":"0.0.0","metadata":["*"]}}}},"ScopedTable":{"id":"ScopedTable","path":"add-to-resource-policy-test-stack/ScopedTable","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.Table","version":"0.0.0","metadata":[{"tableName":"*","partitionKey":{"name":"*","type":"S"},"removalPolicy":"destroy"}]},"children":{"Resource":{"id":"Resource","path":"add-to-resource-policy-test-stack/ScopedTable/Resource","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.CfnTable","version":"0.0.0"},"attributes":{"aws:cdk:cloudformation:type":"AWS::DynamoDB::Table","aws:cdk:cloudformation:props":{"attributeDefinitions":[{"attributeName":"id","attributeType":"S"}],"keySchema":[{"attributeName":"id","keyType":"HASH"}],"provisionedThroughput":{"readCapacityUnits":5,"writeCapacityUnits":5},"resourcePolicy":{"policyDocument":{"Statement":[{"Action":["dynamodb:GetItem","dynamodb:Query"],"Effect":"Allow","Principal":{"AWS":{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":iam::",{"Ref":"AWS::AccountId"},":root"]]}},"Resource":{"Fn::Sub":"arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-scoped-table"}}],"Version":"2012-10-17"}},"tableName":"my-explicit-scoped-table"}}},"ScalingRole":{"id":"ScalingRole","path":"add-to-resource-policy-test-stack/ScopedTable/ScalingRole","constructInfo":{"fqn":"aws-cdk-lib.Resource","version":"0.0.0","metadata":["*"]}}}},"BootstrapVersion":{"id":"BootstrapVersion","path":"add-to-resource-policy-test-stack/BootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnParameter","version":"0.0.0"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"add-to-resource-policy-test-stack/CheckBootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnRule","version":"0.0.0"}}}},"add-to-resource-policy-integ-test":{"id":"add-to-resource-policy-integ-test","path":"add-to-resource-policy-integ-test","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTest","version":"0.0.0"},"children":{"DefaultTest":{"id":"DefaultTest","path":"add-to-resource-policy-integ-test/DefaultTest","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTestCase","version":"0.0.0"},"children":{"Default":{"id":"Default","path":"add-to-resource-policy-integ-test/DefaultTest/Default","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"DeployAssert":{"id":"DeployAssert","path":"add-to-resource-policy-integ-test/DefaultTest/DeployAssert","constructInfo":{"fqn":"aws-cdk-lib.Stack","version":"0.0.0"},"children":{"BootstrapVersion":{"id":"BootstrapVersion","path":"add-to-resource-policy-integ-test/DefaultTest/DeployAssert/BootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnParameter","version":"0.0.0"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"add-to-resource-policy-integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnRule","version":"0.0.0"}}}}}}}},"Tree":{"id":"Tree","path":"Tree","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}}}} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.ts new file mode 100644 index 0000000000000..a79db764a8054 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.add-to-resource-policy.ts @@ -0,0 +1,80 @@ +/** + * Integration test for DynamoDB Table.addToResourcePolicy() method + * + * This test validates the fix for issue #35062: "(aws-dynamodb): `addToResourcePolicy` has no effect" + * + * WHAT WE'RE TESTING: + * - The addToResourcePolicy() method was broken - it had "no effect" when called + * - Resource policies weren't being added to the CloudFormation template + * - This created a security gap where developers thought they were securing tables but policies weren't applied + * + * TEST VALIDATION: + * 1. Creates DynamoDB tables with different resource policy configurations + * 2. Tests both wildcard resources (for auto-generated names) and scoped resources (for explicit names) + * 3. Verifies policies get added to CloudFormation templates with correct structure + * 4. Ensures both patterns work without circular dependencies + * + * @see https://github.com/aws/aws-cdk/issues/35062 + */ + +import { App, Fn, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'; +import * as iam from 'aws-cdk-lib/aws-iam'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +export class TestStack extends Stack { + public readonly wildcardTable: dynamodb.Table; + public readonly scopedTable: dynamodb.Table; + + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + // TEST 1: Table with wildcard resource policy (auto-generated name) + // This is the standard pattern to avoid circular dependencies + this.wildcardTable = new dynamodb.Table(this, 'WildcardTable', { + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + removalPolicy: RemovalPolicy.DESTROY, + }); + + // Add resource policy with wildcard resources + this.wildcardTable.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:PutItem', 'dynamodb:Query'], + principals: [new iam.AccountRootPrincipal()], + resources: ['*'], // Use wildcard to avoid circular dependency - standard pattern for resource policies + })); + + // TEST 2: Table with scoped resource policy (explicit table name) + // This demonstrates how to use scoped resources when table name is known at synthesis time + this.scopedTable = new dynamodb.Table(this, 'ScopedTable', { + tableName: 'my-explicit-scoped-table', // Explicit name enables scoped ARN construction + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + removalPolicy: RemovalPolicy.DESTROY, + }); + + // Add resource policy with properly scoped resource using explicit table name + // This works because table name is known at synthesis time (no circular dependency) + this.scopedTable.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:Query'], + principals: [new iam.AccountRootPrincipal()], + // Use CloudFormation intrinsic function to construct table ARN with known table name + resources: [Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-scoped-table')], + })); + } +} + +// Test Setup +const app = new App(); +const stack = new TestStack(app, 'add-to-resource-policy-test-stack'); + +// Integration Test Configuration +new IntegTest(app, 'add-to-resource-policy-integ-test', { + testCases: [stack], +}); + diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/cdk.out index 1f0068d32659a..523a9aac37cbf 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"36.0.0"} \ No newline at end of file +{"version":"48.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/integ.json index 61d445eeb6f54..820d2f77794ca 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/integ.json @@ -1,22 +1,13 @@ { - "version": "36.0.0", + "version": "48.0.0", "testCases": { "resource-policy-integ-test/DefaultTest": { "stacks": [ "resource-policy-stack" ], - "regions": [ - "us-east-1" - ], - "cdkCommandOptions": { - "deploy": { - "args": { - "rollback": true - } - } - }, "assertionStack": "resource-policy-integ-test/DefaultTest/DeployAssert", "assertionStackName": "resourcepolicyintegtestDefaultTestDeployAssert9778837B" } - } + }, + "minimumCliVersion": "2.1027.0" } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/manifest.json index ffa0d288174ae..995ed49a20870 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "36.0.0", + "version": "48.0.0", "artifacts": { "resource-policy-stack.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/e3fcb6ddf5b25ca1df397996de10e74311360d17c1f51a46151edee98629d5d1.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/12dfe1edf07578c7dac3da48535fa690c0a0ab96999c342385c7e0a8eadba186.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,19 +34,53 @@ "resource-policy-stack.assets" ], "metadata": { + "/resource-policy-stack/TableTest1": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "partitionKey": { + "name": "*", + "type": "S" + }, + "removalPolicy": "destroy", + "resourcePolicy": "*" + } + } + ], "/resource-policy-stack/TableTest1/Resource": [ { "type": "aws:cdk:logicalId", "data": "TableTest143E55AA2" } ], + "/resource-policy-stack/TableTest1/ScalingRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/resource-policy-stack/TableTest2": [ + { + "type": "aws:cdk:analytics:construct", + "data": { + "partitionKey": { + "name": "*", + "type": "S" + }, + "removalPolicy": "destroy" + } + } + ], "/resource-policy-stack/TableTest2/Resource": [ { "type": "aws:cdk:logicalId", - "data": "TableTest21D137FC9", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "TableTest21D137FC9" + } + ], + "/resource-policy-stack/TableTest2/ScalingRole": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" } ], "/resource-policy-stack/BootstrapVersion": [ @@ -117,6 +151,485 @@ "properties": { "file": "tree.json" } + }, + "aws-cdk-lib/feature-flag-report": { + "type": "cdk:feature-flag-report", + "properties": { + "module": "aws-cdk-lib", + "flags": { + "@aws-cdk/aws-signer:signingProfileNamePassedToCfn": { + "recommendedValue": true, + "explanation": "Pass signingProfileName to CfnSigningProfile" + }, + "@aws-cdk/core:newStyleStackSynthesis": { + "recommendedValue": true, + "explanation": "Switch to new stack synthesis method which enables CI/CD", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:stackRelativeExports": { + "recommendedValue": true, + "explanation": "Name exports based on the construct paths relative to the stack, rather than the global construct path", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": { + "recommendedValue": true, + "explanation": "Disable implicit openListener when custom security groups are provided" + }, + "@aws-cdk/aws-rds:lowercaseDbIdentifier": { + "recommendedValue": true, + "explanation": "Force lowercasing of RDS Cluster names in CDK", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": { + "recommendedValue": true, + "explanation": "Allow adding/removing multiple UsagePlanKeys independently", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeVersionProps": { + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeLayerVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`." + }, + "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": { + "recommendedValue": true, + "explanation": "Enable this feature flag to have cloudfront distributions use the security policy TLSv1.2_2021 by default.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:checkSecretUsage": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this flag to make it impossible to accidentally use SecretValues in unsafe locations" + }, + "@aws-cdk/core:target-partitions": { + "recommendedValue": [ + "aws", + "aws-cn" + ], + "explanation": "What regions to include in lookup tables of environment agnostic stacks" + }, + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": { + "userValue": true, + "recommendedValue": true, + "explanation": "ECS extensions will automatically add an `awslogs` driver if no logging is specified" + }, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to have Launch Templates generated by the `InstanceRequireImdsv2Aspect` use unique names." + }, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": { + "userValue": true, + "recommendedValue": true, + "explanation": "ARN format used by ECS. In the new ARN format, the cluster name is part of the resource ID." + }, + "@aws-cdk/aws-iam:minimizePolicies": { + "userValue": true, + "recommendedValue": true, + "explanation": "Minimize IAM policies by combining Statements" + }, + "@aws-cdk/core:validateSnapshotRemovalPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Error on snapshot removal policies on resources that do not support it." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate key aliases that include the stack name" + }, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to create an S3 bucket policy by default in cases where an AWS service would automatically create the Policy if one does not exist." + }, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict KMS key policy for encrypted Queues a bit more" + }, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make default CloudWatch Role behavior safe for multiple API Gateways in one environment" + }, + "@aws-cdk/core:enablePartitionLiterals": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make ARNs concrete if AWS partition is known" + }, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": { + "userValue": true, + "recommendedValue": true, + "explanation": "Event Rules may only push to encrypted SQS queues in the same account" + }, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": { + "userValue": true, + "recommendedValue": true, + "explanation": "Avoid setting the \"ECS\" deployment controller when adding a circuit breaker" + }, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature to by default create default policy names for imported roles that depend on the stack the role is in." + }, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use S3 Bucket Policy instead of ACLs for Server Access Logging" + }, + "@aws-cdk/aws-route53-patters:useCertificate": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use the official `Certificate` resource instead of `DnsValidatedCertificate`" + }, + "@aws-cdk/customresources:installLatestAwsSdkDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "Whether to install the latest SDK by default in AwsCustomResource" + }, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use unique resource name for Database Proxy" + }, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Remove CloudWatch alarms from deployment group" + }, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include authorizer configuration in the calculation of the API deployment logical ID." + }, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": { + "userValue": true, + "recommendedValue": true, + "explanation": "Define user data for a launch template by default when a machine image is provided." + }, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": { + "userValue": true, + "recommendedValue": true, + "explanation": "SecretTargetAttachments uses the ResourcePolicy of the attached Secret." + }, + "@aws-cdk/aws-redshift:columnId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Whether to use an ID to track Redshift column changes" + }, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable AmazonEMRServicePolicy_v2 managed policies" + }, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict access to the VPC default security group" + }, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a unique id for each RequestValidator added to a method" + }, + "@aws-cdk/aws-kms:aliasNameRef": { + "userValue": true, + "recommendedValue": true, + "explanation": "KMS Alias name and keyArn will have implicit reference to KMS Key" + }, + "@aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable grant methods on Aliases imported by name to use kms:ResourceAliases condition" + }, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a launch template when creating an AutoScalingGroup" + }, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include the stack prefix in the stack name generation process" + }, + "@aws-cdk/aws-efs:denyAnonymousAccess": { + "userValue": true, + "recommendedValue": true, + "explanation": "EFS denies anonymous clients accesses" + }, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables support for Multi-AZ with Standby deployment for opensearch domains" + }, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables aws-lambda-nodejs.Function to use the latest available NodeJs runtime as the default" + }, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, mount targets will have a stable logicalId that is linked to the associated subnet." + }, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change." + }, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, will always use the arn for identifiers for CfnSourceApiAssociation in the GraphqlApi construct rather than id." + }, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials." + }, + "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the CodeCommit source action is using the default branch name 'main'." + }, + "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default value for crossAccountKeys to false." + }, + "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default pipeline type to V2." + }, + "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, IAM Policy created from KMS key grant will reduce the resource scope to this key only." + }, + "@aws-cdk/pipelines:reduceAssetRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from PipelineAssetsFileRole trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-eks:nodegroupNameAttribute": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, nodegroupName attribute of the provisioned EKS NodeGroup will not have the cluster name prefix." + }, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default volume type of the EBS volume will be GP3" + }, + "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, remove default deployment alarm settings" + }, + "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, the custom resource used for `AwsCustomResource` will configure the `logApiResponseData` property as true by default" + }, + "@aws-cdk/aws-s3:keepNotificationInImportedBucket": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, Adding notifications to a bucket in the current stack will not remove notification from imported stack." + }, + "@aws-cdk/aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask": { + "recommendedValue": true, + "explanation": "When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:explicitStackTags": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, stack tags need to be assigned explicitly on a Stack." + }, + "@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": { + "userValue": false, + "recommendedValue": false, + "explanation": "When set to true along with canContainersAccessInstanceRole=false in ECS cluster, new updated commands will be added to UserData to block container accessing IMDS. **Applicable to Linux only. IMPORTANT: See [details.](#aws-cdkaws-ecsenableImdsBlockingDeprecatedFeature)**" + }, + "@aws-cdk/aws-ecs:disableEcsImdsBlocking": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, CDK synth will throw exception if canContainersAccessInstanceRole is false. **IMPORTANT: See [details.](#aws-cdkaws-ecsdisableEcsImdsBlocking)**" + }, + "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, we will only grant the necessary permissions when users specify cloudwatch log group through logConfiguration" + }, + "@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled will allow you to specify a resource policy per replica, and not copy the source table policy to all replicas" + }, + "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, initOptions.timeout and resourceSignalTimeout values will be summed together." + }, + "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a Lambda authorizer Permission created when using GraphqlApi will be properly scoped with a SourceArn." + }, + "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn`" + }, + "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CFN templates added with `cfn-include` will error if the template contains Resource Update or Create policies with CFN Intrinsics that include non-primitive values." + }, + "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, both `@aws-sdk` and `@smithy` packages will be excluded from the Lambda Node.js 18.x runtime to prevent version mismatches in bundled applications." + }, + "@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resource of IAM Run Ecs policy generated by SFN EcsRunTask will reference the definition, instead of constructing ARN." + }, + "@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the BastionHost construct will use the latest Amazon Linux 2023 AMI, instead of Amazon Linux 2." + }, + "@aws-cdk/core:aspectStabilization": { + "recommendedValue": true, + "explanation": "When enabled, a stabilization loop will be run when invoking Aspects during synthesis.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, use a new method for DNS Name of user pool domain target without creating a custom resource." + }, + "@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default security group ingress rules will allow IPv6 ingress from anywhere" + }, + "@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default behaviour of OIDC provider will reject unauthorized connections" + }, + "@aws-cdk/core:enableAdditionalMetadataCollection": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will expand the scope of usage data collected to better inform CDK development and improve communication for security concerns and emerging issues." + }, + "@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": { + "userValue": false, + "recommendedValue": false, + "explanation": "[Deprecated] When enabled, Lambda will create new inline policies with AddToRolePolicy instead of adding to the Default Policy Statement" + }, + "@aws-cdk/aws-s3:setUniqueReplicationRoleName": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will automatically generate a unique role name that is used for s3 object replication." + }, + "@aws-cdk/pipelines:reduceStageRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from Stage addActions trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-events:requireEventBusPolicySid": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, grantPutEventsTo() will use resource policies with Statement IDs for service principals." + }, + "@aws-cdk/core:aspectPrioritiesMutating": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, Aspects added by the construct library on your behalf will be given a priority of MUTATING." + }, + "@aws-cdk/aws-dynamodb:retainTableReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, table replica will be default to the removal policy of source table unless specified otherwise." + }, + "@aws-cdk/cognito:logUserPoolClientSecretValue": { + "recommendedValue": false, + "explanation": "When disabled, the value of the user pool client secret will not be logged in the custom resource lambda function logs." + }, + "@aws-cdk/pipelines:reduceCrossAccountActionRoleTrustScope": { + "recommendedValue": true, + "explanation": "When enabled, scopes down the trust policy for the cross-account action role", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resultWriterV2 property of DistributedMap will be used insted of resultWriter" + }, + "@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": { + "userValue": true, + "recommendedValue": true, + "explanation": "Add an S3 trust policy to a KMS key resource policy for SNS subscriptions." + }, + "@aws-cdk/aws-ec2:requirePrivateSubnetsForEgressOnlyInternetGateway": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the EgressOnlyGateway resource is only created if private subnets are defined in the dual-stack VPC." + }, + "@aws-cdk/aws-ec2-alpha:useResourceIdForVpcV2Migration": { + "recommendedValue": false, + "explanation": "When enabled, use resource IDs for VPC V2 migration" + }, + "@aws-cdk/aws-s3:publicAccessBlockedByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, setting any combination of options for BlockPublicAccess will automatically set true for any options not defined." + }, + "@aws-cdk/aws-lambda:useCdkManagedLogGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK creates and manages loggroup for the lambda function" + } + } + } } - } + }, + "minimumCliVersion": "2.1027.0" } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.assets.json index 7c0077eab1646..3ffcee23ebac8 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.assets.json @@ -1,15 +1,16 @@ { - "version": "36.0.0", + "version": "48.0.0", "files": { - "e3fcb6ddf5b25ca1df397996de10e74311360d17c1f51a46151edee98629d5d1": { + "12dfe1edf07578c7dac3da48535fa690c0a0ab96999c342385c7e0a8eadba186": { + "displayName": "resource-policy-stack Template", "source": { "path": "resource-policy-stack.template.json", "packaging": "file" }, "destinations": { - "current_account-current_region": { + "current_account-current_region-d3441269": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "e3fcb6ddf5b25ca1df397996de10e74311360d17c1f51a46151edee98629d5d1.json", + "objectKey": "12dfe1edf07578c7dac3da48535fa690c0a0ab96999c342385c7e0a8eadba186.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.template.json index 1d36ff78393a6..fdaf720f742ae 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resource-policy-stack.template.json @@ -71,6 +71,32 @@ "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 + }, + "ResourcePolicy": { + "PolicyDocument": { + "Statement": [ + { + "Action": "dynamodb:*", + "Effect": "Allow", + "Principal": { + "AWS": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::127311923021:root" + ] + ] + } + }, + "Resource": "*" + } + ], + "Version": "2012-10-17" + } } }, "UpdateReplacePolicy": "Delete", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resourcepolicyintegtestDefaultTestDeployAssert9778837B.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resourcepolicyintegtestDefaultTestDeployAssert9778837B.assets.json index 0861153b87513..29dd4bfdf5a6a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resourcepolicyintegtestDefaultTestDeployAssert9778837B.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/resourcepolicyintegtestDefaultTestDeployAssert9778837B.assets.json @@ -1,13 +1,14 @@ { - "version": "36.0.0", + "version": "48.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "displayName": "resourcepolicyintegtestDefaultTestDeployAssert9778837B Template", "source": { "path": "resourcepolicyintegtestDefaultTestDeployAssert9778837B.template.json", "packaging": "file" }, "destinations": { - "current_account-current_region": { + "current_account-current_region-d8d86b35": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/tree.json index 72ee67ca075e2..f8255687fe9cf 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.js.snapshot/tree.json @@ -1,225 +1 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "resource-policy-stack": { - "id": "resource-policy-stack", - "path": "resource-policy-stack", - "children": { - "TableTest1": { - "id": "TableTest1", - "path": "resource-policy-stack/TableTest1", - "children": { - "Resource": { - "id": "Resource", - "path": "resource-policy-stack/TableTest1/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", - "aws:cdk:cloudformation:props": { - "attributeDefinitions": [ - { - "attributeName": "id", - "attributeType": "S" - } - ], - "keySchema": [ - { - "attributeName": "id", - "keyType": "HASH" - } - ], - "provisionedThroughput": { - "readCapacityUnits": 5, - "writeCapacityUnits": 5 - }, - "resourcePolicy": { - "policyDocument": { - "Statement": [ - { - "Action": "dynamodb:*", - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::", - { - "Ref": "AWS::AccountId" - }, - ":root" - ] - ] - } - }, - "Resource": "*" - } - ], - "Version": "2012-10-17" - } - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_dynamodb.CfnTable", - "version": "0.0.0" - } - }, - "ScalingRole": { - "id": "ScalingRole", - "path": "resource-policy-stack/TableTest1/ScalingRole", - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - }, - "TableTest2": { - "id": "TableTest2", - "path": "resource-policy-stack/TableTest2", - "children": { - "Resource": { - "id": "Resource", - "path": "resource-policy-stack/TableTest2/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::DynamoDB::Table", - "aws:cdk:cloudformation:props": { - "attributeDefinitions": [ - { - "attributeName": "PK", - "attributeType": "S" - } - ], - "keySchema": [ - { - "attributeName": "PK", - "keyType": "HASH" - } - ], - "provisionedThroughput": { - "readCapacityUnits": 5, - "writeCapacityUnits": 5 - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_dynamodb.CfnTable", - "version": "0.0.0" - } - }, - "ScalingRole": { - "id": "ScalingRole", - "path": "resource-policy-stack/TableTest2/ScalingRole", - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" - } - }, - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "resource-policy-stack/BootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "resource-policy-stack/CheckBootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" - } - }, - "resource-policy-integ-test": { - "id": "resource-policy-integ-test", - "path": "resource-policy-integ-test", - "children": { - "DefaultTest": { - "id": "DefaultTest", - "path": "resource-policy-integ-test/DefaultTest", - "children": { - "Default": { - "id": "Default", - "path": "resource-policy-integ-test/DefaultTest/Default", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0" - } - }, - "DeployAssert": { - "id": "DeployAssert", - "path": "resource-policy-integ-test/DefaultTest/DeployAssert", - "children": { - "BootstrapVersion": { - "id": "BootstrapVersion", - "path": "resource-policy-integ-test/DefaultTest/DeployAssert/BootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" - } - }, - "CheckBootstrapVersion": { - "id": "CheckBootstrapVersion", - "path": "resource-policy-integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion", - "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", - "version": "0.0.0" - } - }, - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" - } - } -} \ No newline at end of file +{"version":"tree-0.1","tree":{"id":"App","path":"","constructInfo":{"fqn":"aws-cdk-lib.App","version":"0.0.0"},"children":{"resource-policy-stack":{"id":"resource-policy-stack","path":"resource-policy-stack","constructInfo":{"fqn":"aws-cdk-lib.Stack","version":"0.0.0"},"children":{"TableTest1":{"id":"TableTest1","path":"resource-policy-stack/TableTest1","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.Table","version":"0.0.0","metadata":[{"partitionKey":{"name":"*","type":"S"},"removalPolicy":"destroy","resourcePolicy":"*"}]},"children":{"Resource":{"id":"Resource","path":"resource-policy-stack/TableTest1/Resource","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.CfnTable","version":"0.0.0"},"attributes":{"aws:cdk:cloudformation:type":"AWS::DynamoDB::Table","aws:cdk:cloudformation:props":{"attributeDefinitions":[{"attributeName":"id","attributeType":"S"}],"keySchema":[{"attributeName":"id","keyType":"HASH"}],"provisionedThroughput":{"readCapacityUnits":5,"writeCapacityUnits":5},"resourcePolicy":{"policyDocument":{"Statement":[{"Action":"dynamodb:*","Effect":"Allow","Principal":{"AWS":{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":iam::",{"Ref":"AWS::AccountId"},":root"]]}},"Resource":"*"}],"Version":"2012-10-17"}}}}},"ScalingRole":{"id":"ScalingRole","path":"resource-policy-stack/TableTest1/ScalingRole","constructInfo":{"fqn":"aws-cdk-lib.Resource","version":"0.0.0","metadata":["*"]}}}},"TableTest2":{"id":"TableTest2","path":"resource-policy-stack/TableTest2","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.Table","version":"0.0.0","metadata":[{"partitionKey":{"name":"*","type":"S"},"removalPolicy":"destroy"}]},"children":{"Resource":{"id":"Resource","path":"resource-policy-stack/TableTest2/Resource","constructInfo":{"fqn":"aws-cdk-lib.aws_dynamodb.CfnTable","version":"0.0.0"},"attributes":{"aws:cdk:cloudformation:type":"AWS::DynamoDB::Table","aws:cdk:cloudformation:props":{"attributeDefinitions":[{"attributeName":"PK","attributeType":"S"}],"keySchema":[{"attributeName":"PK","keyType":"HASH"}],"provisionedThroughput":{"readCapacityUnits":5,"writeCapacityUnits":5},"resourcePolicy":{"policyDocument":{"Statement":[{"Action":"dynamodb:*","Effect":"Allow","Principal":{"AWS":{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":iam::127311923021:root"]]}},"Resource":"*"}],"Version":"2012-10-17"}}}}},"ScalingRole":{"id":"ScalingRole","path":"resource-policy-stack/TableTest2/ScalingRole","constructInfo":{"fqn":"aws-cdk-lib.Resource","version":"0.0.0","metadata":["*"]}}}},"BootstrapVersion":{"id":"BootstrapVersion","path":"resource-policy-stack/BootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnParameter","version":"0.0.0"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"resource-policy-stack/CheckBootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnRule","version":"0.0.0"}}}},"resource-policy-integ-test":{"id":"resource-policy-integ-test","path":"resource-policy-integ-test","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTest","version":"0.0.0"},"children":{"DefaultTest":{"id":"DefaultTest","path":"resource-policy-integ-test/DefaultTest","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTestCase","version":"0.0.0"},"children":{"Default":{"id":"Default","path":"resource-policy-integ-test/DefaultTest/Default","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"DeployAssert":{"id":"DeployAssert","path":"resource-policy-integ-test/DefaultTest/DeployAssert","constructInfo":{"fqn":"aws-cdk-lib.Stack","version":"0.0.0"},"children":{"BootstrapVersion":{"id":"BootstrapVersion","path":"resource-policy-integ-test/DefaultTest/DeployAssert/BootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnParameter","version":"0.0.0"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"resource-policy-integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion","constructInfo":{"fqn":"aws-cdk-lib.CfnRule","version":"0.0.0"}}}}}}}},"Tree":{"id":"Tree","path":"Tree","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}}}} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.ts index 173047c8921bd..6f96c900b1118 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb.policy.ts @@ -38,7 +38,27 @@ export class TestStack extends Stack { removalPolicy: RemovalPolicy.DESTROY, }); - this.tableTwo.grantReadData(new iam.AccountPrincipal('123456789012')); + // IMPORTANT: Cross-account grants with auto-generated table names create circular dependencies + // + // WHY NOT this.tableTwo.grantReadData(new iam.AccountPrincipal('123456789012'))? + // - Cross-account principals cannot have policies attached to them + // - Grant falls back to adding a resource policy to the table + // - Resource policy tries to reference this.tableArn (the table's own ARN) + // - This creates a circular dependency: Table → ResourcePolicy → Table ARN → Table + // - CloudFormation fails with "Circular dependency between resources" + // + // SOLUTIONS: + // 1. Use addToResourcePolicy with wildcard resources (this approach) + // 2. Use explicit table names: tableName: 'my-table-name' (enables scoped resources) + // 3. Use same-account principals (grants go to principal policy, not resource policy) + // + this.tableTwo.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:*'], + // we need a valid account for cross-account principal otherwise it won't deploy + // this account is from fact-table.ts + principals: [new iam.AccountPrincipal('127311923021')], + resources: ['*'], // Wildcard avoids circular dependency - same pattern as KMS + })); } } diff --git a/packages/aws-cdk-lib/aws-dynamodb/README.md b/packages/aws-cdk-lib/aws-dynamodb/README.md index e58f899f3aad5..d5e65a1b3d8d1 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/README.md +++ b/packages/aws-cdk-lib/aws-dynamodb/README.md @@ -816,6 +816,59 @@ Using `resourcePolicy` you can add a [resource policy](https://docs.aws.amazon.c }); ``` +### Adding Resource Policy Statements Dynamically + +You can also add resource policy statements to a table after it's created using the `addToResourcePolicy` method. Following the same pattern as KMS, resource policies use wildcard resources to avoid circular dependencies: + +```ts +const table = new dynamodb.TableV2(this, 'Table', { + partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING }, +}); + +// Standard resource policy (recommended approach) +table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:PutItem', 'dynamodb:Query'], + principals: [new iam.AccountRootPrincipal()], + resources: ['*'], // Wildcard avoids circular dependency - same pattern as KMS +})); + +// Allow specific service access +table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:Query'], + principals: [new iam.ServicePrincipal('lambda.amazonaws.com')], + resources: ['*'], +})); +``` + +#### Scoped Resource Policies (Advanced) + +For scoped resource policies that reference specific table ARNs, you must specify an explicit table name: + +```ts +import { Fn } from 'aws-cdk-lib'; + +// Table with explicit name enables scoped resource policies +const table = new dynamodb.TableV2(this, 'Table', { + tableName: 'my-explicit-table-name', // Required for scoped resources + partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING }, +}); + +// Now you can use scoped resources +table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem'], + principals: [new iam.AccountRootPrincipal()], + resources: [ + Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name'), + Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name/index/*'), + ], +})); +``` + +**Important Limitations:** +- **Auto-generated table names**: Must use `resources: ['*']` to avoid circular dependencies +- **Explicit table names**: Enable scoped resources but lose CDK's automatic naming benefits +- **CloudFormation constraint**: Resource policies cannot reference the resource they're attached to during creation + TableV2 doesn’t support creating a replica and adding a resource-based policy to that replica in the same stack update in Regions other than the Region where you deploy the stack update. To incorporate a resource-based policy into a replica, you'll need to initially deploy the replica without the policy, followed by a subsequent update to include the desired policy. diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts index 134afe2c8be95..6010948d546a4 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts @@ -464,19 +464,12 @@ export abstract class TableBaseV2 extends Resource implements ITableV2, IResourc } /** - * Adds a statement to the resource policy associated with this file system. + * Adds a statement to the resource policy associated with this table. * A resource policy will be automatically created upon the first call to `addToResourcePolicy`. * - * Note that this does not work with imported file systems. + * Note that this does not work with imported tables. * * @param statement The policy statement to add */ - public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult { - this.resourcePolicy = this.resourcePolicy ?? new PolicyDocument({ statements: [] }); - this.resourcePolicy.addStatements(statement); - return { - statementAdded: true, - policyDependable: this, - }; - } + public abstract addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult; } diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts index 379bb11e74fb4..4b2985e94024b 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts @@ -20,7 +20,7 @@ import { validateContributorInsights, } from './shared'; import { ITableV2, TableBaseV2 } from './table-v2-base'; -import { PolicyDocument } from '../../aws-iam'; +import { AddToResourcePolicyResult, PolicyDocument, PolicyStatement } from '../../aws-iam'; import { IStream } from '../../aws-kinesis'; import { IKey, Key } from '../../aws-kms'; import { @@ -523,6 +523,20 @@ export class TableV2 extends TableBaseV2 { this.encryptionKey = attrs.encryptionKey; this.resourcePolicy = resourcePolicy; } + + /** + * Adds a statement to the resource policy associated with this table. + * + * Note: This is a no-op for imported tables since resource policies cannot be modified. + * + * @param _statement The policy statement to add + */ + public addToResourcePolicy(_statement: PolicyStatement): AddToResourcePolicyResult { + // No-op for imported tables - resource policies cannot be modified + return { + statementAdded: false, + }; + } } let tableName: string; @@ -653,6 +667,9 @@ export class TableV2 extends TableBaseV2 { throw new ValidationError('Witness region cannot be specified for a Multi-Region Eventual Consistency (MREC) Global Table - Witness regions are only supported for Multi-Region Strong Consistency (MRSC) Global Tables.', this); } + // Initialize resourcePolicy from props or create empty one (KMS pattern) + this.resourcePolicy = props.resourcePolicy; + const resource = new CfnGlobalTable(this, 'Resource', { tableName: this.physicalName, keySchema: this.keySchema, @@ -694,6 +711,28 @@ export class TableV2 extends TableBaseV2 { } } + /** + * Adds a statement to the resource policy associated with this table. + * A resource policy will be automatically created upon the first call to `addToResourcePolicy`. + * + * Note that this does not work with imported tables. + * + * @param statement The policy statement to add + */ + public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult { + // Initialize resourcePolicy if it doesn't exist + if (!this.resourcePolicy) { + this.resourcePolicy = new PolicyDocument({ statements: [] }); + } + + this.resourcePolicy.addStatements(statement); + + return { + statementAdded: true, + policyDependable: this.resourcePolicy, + }; + } + /** * Add a replica table. * @@ -807,8 +846,8 @@ export class TableV2 extends TableBaseV2 { * @see https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/FEATURE_FLAGS.md */ const resourcePolicy = FeatureFlags.of(this).isEnabled(cxapi.DYNAMODB_TABLEV2_RESOURCE_POLICY_PER_REPLICA) - ? (props.region === this.region ? this.tableOptions.resourcePolicy : props.resourcePolicy) || undefined - : props.resourcePolicy ?? this.tableOptions.resourcePolicy; + ? (props.region === this.region ? this.resourcePolicy : props.resourcePolicy) || undefined + : props.resourcePolicy ?? this.resourcePolicy; const propTags: Record = (props.tags ?? []).reduce((p, item) => ({ ...p, [item.key]: item.value }), {}, diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts index 4a8c65e324932..0aec5a5081026 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts @@ -652,6 +652,11 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc protected readonly regionalArns = new Array(); + /** + * Adds a statement to the resource policy associated with this table. + */ + public abstract addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult; + /** * Adds an IAM policy statement associated with this table to an IAM * principal's policy. @@ -790,23 +795,6 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc return this.combinedGrant(grantee, { keyActions, tableActions: ['dynamodb:*'] }); } - /** - * Adds a statement to the resource policy associated with this file system. - * A resource policy will be automatically created upon the first call to `addToResourcePolicy`. - * - * Note that this does not work with imported file systems. - * - * @param statement The policy statement to add - */ - public addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult { - this.resourcePolicy = this.resourcePolicy ?? new iam.PolicyDocument({ statements: [] }); - this.resourcePolicy.addStatements(statement); - return { - statementAdded: true, - policyDependable: this, - }; - } - /** * Return the given named metric for this Table * @@ -1159,6 +1147,11 @@ export class Table extends TableBase { this.tableStreamArn = tableStreamArn; this.encryptionKey = attrs.encryptionKey; } + + public addToResourcePolicy(_statement: iam.PolicyStatement): iam.AddToResourcePolicyResult { + // Imported tables cannot have resource policies modified + return { statementAdded: false }; + } } let name: string; @@ -1214,7 +1207,7 @@ export class Table extends TableBase { */ public readonly tableStreamArn: string | undefined; - private readonly table: CfnTable; + protected readonly table: CfnTable; private readonly keySchema = new Array(); private readonly attributeDefinitions = new Array(); @@ -1241,6 +1234,8 @@ export class Table extends TableBase { // Enhanced CDK Analytics Telemetry addConstructMetadata(this, props); + this.resourcePolicy = props.resourcePolicy; + const { sseSpecification, encryptionKey } = this.parseEncryption(props); const pointInTimeRecoverySpecification = this.validatePitr(props); @@ -1297,13 +1292,15 @@ export class Table extends TableBase { kinesisStreamSpecification: kinesisStreamSpecification, deletionProtectionEnabled: props.deletionProtection, importSourceSpecification: this.renderImportSourceSpecification(props.importSource), - resourcePolicy: props.resourcePolicy - ? { policyDocument: props.resourcePolicy } - : undefined, - warmThroughput: props.warmThroughput?? undefined, + warmThroughput: props.warmThroughput ?? undefined, }); this.table.applyRemovalPolicy(props.removalPolicy); + // Set up dynamic resourcePolicy that can be modified by addToResourcePolicy + if (this.resourcePolicy) { + this.table.resourcePolicy = { policyDocument: this.resourcePolicy }; + } + this.encryptionKey = encryptionKey; this.tableArn = this.getResourceArnAttribute(this.table.attrArn, { @@ -1334,6 +1331,28 @@ export class Table extends TableBase { this.node.addValidation({ validate: () => this.validateTable() }); } + /** + * Adds a statement to the resource policy associated with this table. + * A resource policy will be automatically created upon the first call to `addToResourcePolicy`. + * + * Note that this does not work with imported tables. + * + * @param statement The policy statement to add + */ + public addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult { + this.resourcePolicy = this.resourcePolicy ?? new iam.PolicyDocument({ statements: [] }); + + this.resourcePolicy.addStatements(statement); + + // Update the CfnTable resourcePolicy property + this.table.resourcePolicy = { policyDocument: this.resourcePolicy }; + + return { + statementAdded: true, + policyDependable: this, + }; + } + /** * Add a global secondary index of table. * @@ -1730,9 +1749,44 @@ export class Table extends TableBase { const onEventHandlerPolicy = new SourceTableAttachedPolicy(this, provider.onEventHandler.role!); const isCompleteHandlerPolicy = new SourceTableAttachedPolicy(this, provider.isCompleteHandler.role!); - // Permissions in the source region - this.grant(onEventHandlerPolicy, 'dynamodb:*'); - this.grant(isCompleteHandlerPolicy, 'dynamodb:DescribeTable'); + // IMPORTANT: Add permissions directly to Lambda role policies instead of using this.grant() + // + // WHY NOT this.grant()? + // - this.grant() uses Grant.addToPrincipalOrResource() which has decision logic + // - For cross-stack scenarios (nested stack Lambda roles), it falls back to resource policy + // - Resource policy tries to reference this.tableArn, creating circular dependency: + // Table → ResourcePolicy → Table ARN → Table (CIRCULAR!) + // - This causes CloudFormation deployment to fail + // + // WHY DIRECT POLICY STATEMENTS? + // - Bypasses Grant decision logic entirely + // - Adds permissions directly to Lambda role policies (no resource policy) + // - Avoids circular dependency while ensuring Lambda functions have required permissions + // - Separates internal permission management from user-facing addToResourcePolicy() + + (onEventHandlerPolicy.policy as iam.ManagedPolicy).addStatements(new iam.PolicyStatement({ + actions: ['dynamodb:*'], + resources: [ + this.tableArn, + Lazy.string({ produce: () => this.hasIndex ? `${this.tableArn}/index/*` : Aws.NO_VALUE }), + ...this.regionalArns, + ...this.regionalArns.map(arn => Lazy.string({ + produce: () => this.hasIndex ? `${arn}/index/*` : Aws.NO_VALUE, + })), + ], + })); + + (isCompleteHandlerPolicy.policy as iam.ManagedPolicy).addStatements(new iam.PolicyStatement({ + actions: ['dynamodb:DescribeTable'], + resources: [ + this.tableArn, + Lazy.string({ produce: () => this.hasIndex ? `${this.tableArn}/index/*` : Aws.NO_VALUE }), + ...this.regionalArns, + ...this.regionalArns.map(arn => Lazy.string({ + produce: () => this.hasIndex ? `${arn}/index/*` : Aws.NO_VALUE, + })), + ], + })); let previousRegion: CustomResource | undefined; let previousRegionCondition: CfnCondition | undefined; diff --git a/packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts b/packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts index 3e0a3b6a352f2..b40f4ef867d95 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/test/dynamodb.test.ts @@ -7,7 +7,7 @@ import * as iam from '../../aws-iam'; import * as kinesis from '../../aws-kinesis'; import * as kms from '../../aws-kms'; import * as s3 from '../../aws-s3'; -import { App, Aws, CfnDeletionPolicy, Duration, PhysicalName, RemovalPolicy, Resource, Stack, Tags } from '../../core'; +import { App, Aws, CfnDeletionPolicy, Duration, Fn, PhysicalName, RemovalPolicy, Resource, Stack, Tags } from '../../core'; import * as cr from '../../custom-resources'; import * as cxapi from '../../cx-api'; import { @@ -3951,6 +3951,139 @@ test('Resource policy test', () => { }); }); +test('addToResourcePolicy allows scoped ARN resources when table has explicit name', () => { + // GIVEN + const app = new App(); + const stack = new Stack(app, 'Stack'); + + // WHEN - Create table with explicit name (enables scoped resource policies) + const table = new Table(stack, 'Table', { + tableName: 'my-explicit-table-name', // Explicit name enables scoped ARN construction + partitionKey: { name: 'id', type: AttributeType.STRING }, + }); + + // With explicit table name, we can use scoped resources without circular dependency + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:Query'], + principals: [new iam.AccountRootPrincipal()], + resources: [ + // This works because table name is known at synthesis time + Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name'), + ], + })); + + // THEN + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { + TableName: 'my-explicit-table-name', + ResourcePolicy: { + PolicyDocument: { + Version: '2012-10-17', + Statement: [ + { + Effect: 'Allow', + Principal: Match.anyValue(), + Action: ['dynamodb:GetItem', 'dynamodb:Query'], + Resource: { + 'Fn::Sub': 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name', + }, + }, + ], + }, + }, + }); +}); + +test('addToResourcePolicy requires wildcard resources with auto-generated table names to prevent circular dependencies', () => { + // This test documents the fundamental limitation of resource policies with auto-generated names + + // GIVEN + const app = new App(); + const stack = new Stack(app, 'Stack'); + + const table = new Table(stack, 'Table', { + partitionKey: { name: 'id', type: AttributeType.STRING }, + // No explicit tableName - CDK will generate unique name + }); + + // LIMITATION: Cannot use table.tableArn or construct scoped ARN because it creates circular dependency + // This would fail: resources: [table.tableArn] + // This would also fail: resources: [Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${TableRef}', { TableRef: cfnTable.ref })] + + // WORKAROUND: Must use wildcard resource (same pattern as KMS) + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem'], + principals: [new iam.AccountRootPrincipal()], + resources: ['*'], // Only option for auto-generated table names + })); + + // THEN - Verify wildcard is preserved + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { + ResourcePolicy: { + PolicyDocument: { + Statement: [ + { + Resource: '*', // Wildcard is the only way to avoid circular dependency + }, + ], + }, + }, + }); +}); + +test('addToResourcePolicy supports multiple statements with wildcard resources to avoid circular dependencies', () => { + // GIVEN + const app = new App(); + const stack = new Stack(app, 'Stack'); + + // WHEN + const table = new Table(stack, 'Table', { + partitionKey: { name: 'id', type: AttributeType.STRING }, + }); + + // Test multiple policy statements with different principals and actions + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:PutItem'], + principals: [new iam.AccountRootPrincipal()], + resources: ['*'], // Wildcard avoids circular dependency - same pattern as KMS + })); + + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:Query'], + principals: [new iam.ArnPrincipal('arn:aws:iam::111122223333:user/testuser')], + resources: ['*'], // Wildcard avoids circular dependency + })); + + // THEN + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::Table', { + ResourcePolicy: { + PolicyDocument: { + Version: '2012-10-17', + Statement: [ + { + Effect: 'Allow', + Principal: { + AWS: Match.anyValue(), // Principal format can vary + }, + Action: ['dynamodb:GetItem', 'dynamodb:PutItem'], + Resource: '*', // Wildcard resource to avoid circular dependency + }, + { + Effect: 'Allow', + Principal: { + AWS: 'arn:aws:iam::111122223333:user/testuser', + }, + Action: 'dynamodb:Query', + Resource: '*', // Wildcard resource + }, + ], + }, + }, + }); +}); + test('Warm Throughput test on-demand', () => { // GIVEN const app = new App(); diff --git a/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts b/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts index 5e430b8be4779..98a716cbf9f6e 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts @@ -1,8 +1,9 @@ import { Match, Template } from '../../assertions'; import { ArnPrincipal, PolicyDocument, PolicyStatement } from '../../aws-iam'; +import * as iam from '../../aws-iam'; import { Stream } from '../../aws-kinesis'; import { Key } from '../../aws-kms'; -import { CfnDeletionPolicy, Lazy, RemovalPolicy, Stack, Tags } from '../../core'; +import { CfnDeletionPolicy, Fn, Lazy, RemovalPolicy, Stack, Tags } from '../../core'; import { AttributeType, Billing, Capacity, GlobalSecondaryIndexPropsV2, TableV2, LocalSecondaryIndexProps, ProjectionType, StreamViewType, TableClass, TableEncryptionV2, @@ -3413,6 +3414,99 @@ describe('MRSC global tables validation', () => { }); }); +test('TableV2 addToResourcePolicy works with wildcard resources', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const table = new TableV2(stack, 'Table', { + partitionKey: { name: 'pk', type: AttributeType.STRING }, + }); + + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:PutItem'], + principals: [new iam.AccountRootPrincipal()], + resources: ['*'], // Wildcard avoids circular dependency - same pattern as KMS + })); + + // THEN + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::GlobalTable', { + Replicas: [ + { + Region: { + Ref: 'AWS::Region', + }, + ResourcePolicy: { + PolicyDocument: { + Version: '2012-10-17', + Statement: [ + { + Effect: 'Allow', + Principal: { + AWS: Match.anyValue(), + }, + Action: ['dynamodb:GetItem', 'dynamodb:PutItem'], + Resource: '*', + }, + ], + }, + }, + }, + ], + }); +}); + +test('TableV2 addToResourcePolicy allows scoped ARN resources when table has explicit name', () => { + // GIVEN + const stack = new Stack(undefined, 'Stack'); + + // WHEN - Create table with explicit name (enables scoped resource policies) + const table = new TableV2(stack, 'Table', { + tableName: 'my-explicit-table-name', // Explicit name enables scoped ARN construction + partitionKey: { name: 'id', type: AttributeType.STRING }, + }); + + // With explicit table name, we can use scoped resources without circular dependency + table.addToResourcePolicy(new iam.PolicyStatement({ + actions: ['dynamodb:GetItem', 'dynamodb:Query'], + principals: [new iam.AccountRootPrincipal()], + resources: [ + // This works because table name is known at synthesis time + Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name'), + ], + })); + + // THEN + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::DynamoDB::GlobalTable', { + Replicas: [ + { + Region: { + Ref: 'AWS::Region', + }, + ResourcePolicy: { + PolicyDocument: { + Version: '2012-10-17', + Statement: [ + { + Effect: 'Allow', + Principal: { + AWS: Match.anyValue(), + }, + Action: ['dynamodb:GetItem', 'dynamodb:Query'], + Resource: { + 'Fn::Sub': 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/my-explicit-table-name', + }, + }, + ], + }, + }, + }, + ], + }); +}); + test('Contributor Insights Specification - tableV2', () => { const stack = new Stack();