Aws-cdk: Resolve parameters using the AWS API at deploy time?

Created on 4 Sep 2019  路  4Comments  路  Source: aws/aws-cdk

: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

  • CDK CLI Version: 1.6.1 (build a09203a)
  • Module Version: 1.6.1
  • OS: OSX
  • Language: TypeScript
@aws-cdcore guidance needs-triage

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mirazmamun picture mirazmamun  路  3Comments

v-do picture v-do  路  3Comments

nzspambot picture nzspambot  路  3Comments

slipdexic picture slipdexic  路  3Comments

NukaCody picture NukaCody  路  3Comments