Skip to content

Commit

Permalink
feat(custom-resources): AwsCustomResource passthrough physicalResourceId
Browse files Browse the repository at this point in the history
when omit it in onUpdate

closes aws#23843
  • Loading branch information
konokenj committed Mar 6, 2023
1 parent a70ff1a commit aecf8c6
Show file tree
Hide file tree
Showing 11 changed files with 1,304 additions and 5 deletions.
Expand Up @@ -86,7 +86,8 @@ export interface AwsSdkCall {

/**
* The physical resource id of the custom resource for this call.
* Mandatory for onCreate or onUpdate calls.
* Mandatory for onCreate call.
* In onUpdate, you can omit this to passthrough it from request.
*
* @default - no physical resource id
*/
Expand Down Expand Up @@ -384,10 +385,12 @@ export class AwsCustomResource extends Construct implements iam.IGrantable {
throw new Error('At least one of `policy` or `role` (or both) must be specified.');
}

for (const call of [props.onCreate, props.onUpdate]) {
if (call && !call.physicalResourceId) {
throw new Error('`physicalResourceId` must be specified for onCreate and onUpdate calls.');
}
if (props.onCreate && !props.onCreate.physicalResourceId) {
throw new Error('`physicalResourceId` must be specified for onCreate call.');
}

if (!props.onCreate && props.onUpdate && !props.onUpdate.physicalResourceId) {
throw new Error('`physicalResourceId` must be specified for onUpdate call when onCreate is omitted.');
}

for (const call of [props.onCreate, props.onUpdate, props.onDelete]) {
Expand Down
@@ -0,0 +1,19 @@
{
"version": "29.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "CustomResourceAthenaDefaultTestDeployAssert7AE6A475.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"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": {}
}
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"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."
}
]
}
}
}

Large diffs are not rendered by default.

@@ -0,0 +1,32 @@
{
"version": "29.0.0",
"files": {
"a268caa53756f51bda8ad5f499be4ed8484a81b314811806fbb66f874837c476": {
"source": {
"path": "asset.a268caa53756f51bda8ad5f499be4ed8484a81b314811806fbb66f874837c476",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "a268caa53756f51bda8ad5f499be4ed8484a81b314811806fbb66f874837c476.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"2c3b2903e60f617f0a14d38131e69d5d24c04a48700857dfc3c7322c1973749b": {
"source": {
"path": "aws-cdk-customresources-athena.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "2c3b2903e60f617f0a14d38131e69d5d24c04a48700857dfc3c7322c1973749b.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
@@ -0,0 +1,235 @@
{
"Resources": {
"AthenaResultBucketDF85B968": {
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"AthenaExecRole1895AF29": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "athena.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/AmazonAthenaFullAccess"
]
]
}
]
}
},
"CustomResourceRoleAB1EF463": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
],
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "iam:PassRole",
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"AthenaExecRole1895AF29",
"Arn"
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "PassRolePolicy"
},
{
"PolicyDocument": {
"Statement": [
{
"Action": [
"athena:CreateWorkGroup",
"athena:DeleteWorkGroup"
],
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
"PolicyName": "AthenaWorkGroupPolicy"
},
{
"PolicyDocument": {
"Statement": [
{
"Action": [
"athena:CreateNotebook",
"athena:DeleteNotebook",
"athena:UpdateNotebookMetadata"
],
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
"PolicyName": "AthenaNotebookPolicy"
}
]
}
},
"AthenaWorkGroupA2C2329E": {
"Type": "Custom::AthenaWorkGroup",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"AWS679f53fac002430cb0da5b7982bd22872D164C4C",
"Arn"
]
},
"Create": {
"Fn::Join": [
"",
[
"{\"service\":\"Athena\",\"action\":\"createWorkGroup\",\"physicalResourceId\":{\"id\":\"TestWG\"},\"parameters\":{\"Name\":\"TestWG\",\"Configuration\":{\"ExecutionRole\":\"",
{
"Fn::GetAtt": [
"AthenaExecRole1895AF29",
"Arn"
]
},
"\",\"ResultConfiguration\":{\"OutputLocation\":\"s3://",
{
"Ref": "AthenaResultBucketDF85B968"
},
"\"},\"EngineVersion\":{\"SelectedEngineVersion\":\"PySpark engine version 3\"}}}}"
]
]
},
"Delete": "{\"service\":\"Athena\",\"action\":\"deleteWorkGroup\",\"parameters\":{\"WorkGroup\":\"TestWG\"}}",
"InstallLatestAwsSdk": true
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"AWS679f53fac002430cb0da5b7982bd22872D164C4C": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "a268caa53756f51bda8ad5f499be4ed8484a81b314811806fbb66f874837c476.zip"
},
"Role": {
"Fn::GetAtt": [
"CustomResourceRoleAB1EF463",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "nodejs14.x",
"Timeout": 180
},
"DependsOn": [
"CustomResourceRoleAB1EF463"
]
},
"AthenaNotebook878CD9ED": {
"Type": "Custom::AthenaNotebook",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"AWS679f53fac002430cb0da5b7982bd22872D164C4C",
"Arn"
]
},
"Create": "{\"service\":\"Athena\",\"action\":\"createNotebook\",\"physicalResourceId\":{\"responsePath\":\"NotebookId\"},\"parameters\":{\"WorkGroup\":\"TestWG\",\"Name\":\"MyNotebook1\"}}",
"Update": "{\"service\":\"Athena\",\"action\":\"updateNotebookMetadata\",\"parameters\":{\"Name\":\"MyNotebook1\",\"NotebookId\":\"PHYSICAL:RESOURCEID:\"}}",
"Delete": "{\"service\":\"Athena\",\"action\":\"deleteNotebook\",\"parameters\":{\"NotebookId\":\"PHYSICAL:RESOURCEID:\"}}",
"InstallLatestAwsSdk": true
},
"DependsOn": [
"AthenaWorkGroupA2C2329E"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"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."
}
]
}
}
}
@@ -0,0 +1 @@
{"version":"29.0.0"}
@@ -0,0 +1,12 @@
{
"version": "29.0.0",
"testCases": {
"CustomResourceAthena/DefaultTest": {
"stacks": [
"aws-cdk-customresources-athena"
],
"assertionStack": "CustomResourceAthena/DefaultTest/DeployAssert",
"assertionStackName": "CustomResourceAthenaDefaultTestDeployAssert7AE6A475"
}
}
}

0 comments on commit aecf8c6

Please sign in to comment.