Closed pierreis closed 5 years ago
My understanding is that the idiomatic CDK way of doing this would be to add a AwsCustomResource to perform SDK calls at Deploy Time.
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_custom-resources.AwsCustomResource.html
Okay, thanks. The doc is not very clear IMHO. Here is what I tried:
// Get MediaConvert endpoint
const getParameter = new AwsCustomResource(this, 'GetMediaConvertEndpoint', {
onUpdate: {
service: 'MediaConvert',
action: 'describeEndpoints',
parameters: {
MaxResults: 0,
},
physicalResourceIdPath: 'Endpoints.0.Url',
}
});
// Handler
const handler = new Function(this, "MediaHandler", {
runtime: Runtime.NODEJS_8_10,
code: Code.asset('../resources'),
handler: 'process.main',
environment: {
MEDIA_ENDPOINT: getParameter.getData('Endpoints.0.Url') // Error here: IResolvable is not assignable to string
}
});
I am getting a TS compilation error:
Type '{ MEDIA_ENDPOINT: IResolvable; }' is not assignable to type '{ [key: string]: string; }'.
Property 'MEDIA_ENDPOINT' is incompatible with index signature.
Type 'IResolvable' is not assignable to type 'string'.ts(2322)
I cannot really find any indication on how to resolve Resolvable values at deploy time.
Ok, it was just a missing toString()
call on the resolvable.
I would suggest the docs to make this clear with some example. The ones for custom resources seem to be pretty outdated.
Hi @pierreis, I'm glad your issue got resolved! 👍 I will close this issue. If you want to, feel free to open a PR to update the docs. If not, you can simply open a new issue to specifically address the docs being unclear.
:question: General Issue
The Question
The CDK currently implements deploy-time resolution for certain pieces of data, such as SSM parameters. Is there a specific API we can use to call the AWS API programmatically at deploy time to get some custom information?
My use-case is obtaining the Elemental MediaConvert endpoint at deploy time, in order to set it as a lambda environment variable.
Environment