AwsCustomResourceProps Struct
Properties for AwsCustomResource.
Note that at least onCreate, onUpdate or onDelete must be specified.
| Source | custom-resources/lib/aws-custom-resource/aws-custom-resource.ts |
|---|---|
| Type last changed |
Example
const crossAccountRoleArn = 'arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName'; // arn of role deployed in separate account
const callRegion = 'us-west-1'; // sdk call to be made in specified region (optional)
new cr.AwsCustomResource(this, 'CrossAccount', {
onCreate: {
assumedRoleArn: crossAccountRoleArn,
region: callRegion, // optional
service: 'sts',
action: 'GetCallerIdentity',
physicalResourceId: cr.PhysicalResourceId.of('id'),
},
policy: cr.AwsCustomResourcePolicy.fromStatements([iam.PolicyStatement.fromJson({
Effect: "Allow",
Action: "sts:AssumeRole",
Resource: crossAccountRoleArn,
})]),
});
cross_account_role_arn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName" # arn of role deployed in separate account
call_region = "us-west-1" # sdk call to be made in specified region (optional)
cr.AwsCustomResource(self, "CrossAccount",
on_create=cr.AwsSdkCall(
assumed_role_arn=cross_account_role_arn,
region=call_region, # optional
service="sts",
action="GetCallerIdentity",
physical_resource_id=cr.PhysicalResourceId.of("id")
),
policy=cr.AwsCustomResourcePolicy.from_statements([iam.PolicyStatement.from_json({
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": cross_account_role_arn
})])
)
String crossAccountRoleArn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName"; // arn of role deployed in separate account
String callRegion = "us-west-1"; // sdk call to be made in specified region (optional)
// sdk call to be made in specified region (optional)
AwsCustomResource.Builder.create(this, "CrossAccount")
.onCreate(AwsSdkCall.builder()
.assumedRoleArn(crossAccountRoleArn)
.region(callRegion) // optional
.service("sts")
.action("GetCallerIdentity")
.physicalResourceId(PhysicalResourceId.of("id"))
.build())
.policy(AwsCustomResourcePolicy.fromStatements(List.of(PolicyStatement.fromJson(Map.of(
"Effect", "Allow",
"Action", "sts:AssumeRole",
"Resource", crossAccountRoleArn)))))
.build();
// Install: dotnet add package Amazon.CDK.Lib
var crossAccountRoleArn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName"; // arn of role deployed in separate account
var callRegion = "us-west-1"; // sdk call to be made in specified region (optional)
// sdk call to be made in specified region (optional)
new AwsCustomResource(this, "CrossAccount", new AwsCustomResourceProps {
OnCreate = new AwsSdkCall {
AssumedRoleArn = crossAccountRoleArn,
Region = callRegion, // optional
Service = "sts",
Action = "GetCallerIdentity",
PhysicalResourceId = PhysicalResourceId.Of("id")
},
Policy = AwsCustomResourcePolicy.FromStatements(new [] { PolicyStatement.FromJson(new Dictionary<string, string> {
{ "Effect", "Allow" },
{ "Action", "sts:AssumeRole" },
{ "Resource", crossAccountRoleArn }
}) })
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
crossAccountRoleArn := "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName" // arn of role deployed in separate account
callRegion := "us-west-1" // sdk call to be made in specified region (optional)
// sdk call to be made in specified region (optional)
cr.NewAwsCustomResource(this, jsii.String("CrossAccount"), &AwsCustomResourceProps{
OnCreate: &AwsSdkCall{
AssumedRoleArn: crossAccountRoleArn,
Region: callRegion,
// optional
Service: jsii.String("sts"),
Action: jsii.String("GetCallerIdentity"),
PhysicalResourceId: cr.PhysicalResourceId_Of(jsii.String("id")),
},
Policy: cr.AwsCustomResourcePolicy_FromStatements([]PolicyStatement{
iam.PolicyStatement_FromJson(map[string]*string{
"Effect": jsii.String("Allow"),
"Action": jsii.String("sts:AssumeRole"),
"Resource": crossAccountRoleArn,
}),
}),
})
Properties
functionNameoptionalstringfunction_nameoptionalstrfunctionNameoptionalStringFunctionNameoptionalstringFunctionNameoptional*string #Default: AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.
The function name will remain the same after the first AwsCustomResource is created in a stack.
installLatestAwsSdkoptionalbooleaninstall_latest_aws_sdkoptionalboolinstallLatestAwsSdkoptionalBooleanInstallLatestAwsSdkoptionalboolInstallLatestAwsSdkoptional*bool #Default: The value of @aws-cdk/customresources:installLatestAwsSdkDefault, otherwise true
notes
If not specified, this uses whatever JavaScript SDK version is the default in AWS Lambda at the time of execution.
Otherwise, installs the latest version from 'npmjs.com'. The installation takes around 60 seconds and requires internet connectivity.
The default can be controlled using the context key @aws-cdk/customresources:installLatestAwsSdkDefault is.
logGroupoptionalILogGroupReflog_groupoptionalILogGroupReflogGroupoptionalILogGroupRefLogGroupoptionalILogGroupRefLogGroupoptionalILogGroupRef #Default: a default log group created by AWS Lambda
Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16. If you are deploying to another type of region, please check regional availability first.
logRetentionoptionalRetentionDayslog_retentionoptionalRetentionDayslogRetentionoptionalRetentionDaysLogRetentionoptionalRetentionDaysLogRetentionoptionalRetentionDays = logs.RetentionDays.INFINITE #This is a legacy API and we strongly recommend you migrate to logGroup if you can. logGroup allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
memorySizeoptionalnumbermemory_sizeoptionalint | floatmemorySizeoptionalNumberMemorySizeoptionaldoubleMemorySizeoptional*float64 #Default: 512 mega in case if installLatestAwsSdk is false.
onCreateoptionalAwsSdkCallon_createoptionalAwsSdkCallonCreateoptionalAwsSdkCallOnCreateoptionalAwsSdkCallOnCreateoptionalAwsSdkCall #Default: the call when the resource is updated
onDeleteoptionalAwsSdkCallon_deleteoptionalAwsSdkCallonDeleteoptionalAwsSdkCallOnDeleteoptionalAwsSdkCallOnDeleteoptionalAwsSdkCall #Default: no call
onUpdateoptionalAwsSdkCallon_updateoptionalAwsSdkCallonUpdateoptionalAwsSdkCallOnUpdateoptionalAwsSdkCallOnUpdateoptionalAwsSdkCall #Default: no call
policyoptionalAwsCustomResourcePolicypolicyoptionalAwsCustomResourcePolicypolicyoptionalAwsCustomResourcePolicyPolicyoptionalAwsCustomResourcePolicyPolicyoptionalAwsCustomResourcePolicy #Default: no policy added
notes
The custom resource also implements iam.IGrantable, making it possible to use the grantXxx() methods.
As this custom resource uses a singleton Lambda function, it's important to note the that function's role will eventually accumulate the permissions/grants from all resources.
Note that a policy must be specified if role is not provided, as by default a new role is created which requires policy changes to access resources.
removalPolicyoptionalRemovalPolicyremoval_policyoptionalRemovalPolicyremovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicy = cdk.RemovalPolicy.Destroy #resourceTypeoptionalstringresource_typeoptionalstrresourceTypeoptionalStringResourceTypeoptionalstringResourceTypeoptional*string = Custom::AWS #Default: a new role is created
This role will apply to all AwsCustomResource instances in the stack. The role must be assumable by the lambda.amazonaws.com service principal.
serviceTimeoutoptionalDurationservice_timeoutoptionalDurationserviceTimeoutoptionalDurationServiceTimeoutoptionalDurationServiceTimeoutoptionalDuration = Duration.seconds(3600) #notes
You should not need to set this property. It is intended to allow quick turnaround even if the implementor of the custom resource forgets to include a try/catch. We have included the try/catch, and AWS service calls usually do not take an hour to complete.
The value must be between 1 second and 3600 seconds.
timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration = Duration.minutes(2) #Default: the function is not provisioned inside a vpc.
vpcSubnetsoptionalSubnetSelectionvpc_subnetsoptionalSubnetSelectionvpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelection #Default: the Vpc default strategy if not specified
Only used if 'vpc' is supplied. Note: internet access for Lambdas requires a NAT gateway, so picking Public subnets is not allowed.