-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomResource serviceToken must be a string even though return type is object #1421
Comments
You should be able to just invoke Thanks to this mechanism, you can simplify your solution even more. You could technically do this: serviceToken: `arn:aws:sns:${new cdk.AwsRegion()}:${new cdk.AwsAccountId()}:CloudFormationInterface` In java this will look like this I guess: "arn:aws:sns: " + new AwsRegion() + ":" + new AwsAccountId() + ":CloudFormationInterface" In this usage, The above will resolve to: {
"Fn::Join": [
"",
[
"arn:aws:sns:",
{ "Ref": "AWS::Region" },
":",
{ "Ref": "AWS::AccountId" },
":CloudFormationInterface"
]
]
} The best option would probably not to construct ARNs yourself, but use serviceToken: cdk.ArnUtils.fromComponents({
service: 'sns',
resource: 'CloudFormationInterface'
}) Which resolves to the following, which is even "more accurate" because it takes into account the AWS partition: {
"Fn::Join": [
"",
[
"arn:",
{ "Ref": "AWS::Partition" },
":sns:",
{ "Ref": "AWS::Region" },
":",
{ "Ref": "AWS::AccountId" },
":CloudFormationInterface"
]
]
} We are trying to build the CDK such that it can be used for both use cases, but optimizing for the "native" use case (the one you refer to "generate + deploy"). |
Thanks for all that info, very useful. I can see that I'm actually doing it the "wrong way". As an aside, the Out of interest, is there a way to generate cloudformation which uses |
Ahh, sorry. I just saw |
I'm migrating our existing hand-crafted CF templates to CDK (Java). We have some custom resources which I'm implementing by extending
CustomResource
.I've run into an issue with
CustomResourceProps.getServiceToken()
which has a return type ofObject
, and want to return a function to match our old templates. Our old templates returned aSub
function like this:Which I've implemented as a simple java object (
Ref
), with a single field. Then, I've overridden theCustomResourceProps.getServiceToken()
to return aRef
object. When I synthesize the template, I get the following error:Is this expected behaviour? In general, is it expected that the CDK would be used to generate and execute the CF template? Or could it be used to generate the template, which is then deployed by some other method. I can see that if we expect the CDK to be used to generate and deploy the template, then there's no need to support the template functions, as we can dynamically change those as the template is created. However, we currently generate one template, and deploy it to different environments using parameters/functions to modify the behaviour. To use the CDK for this, I would need CDK support to generate templates containing template functions.
The text was updated successfully, but these errors were encountered: