Search code examples
amazon-web-servicesaws-lambdaaws-cloudformationaws-cdk

How to get the AWS IoT custom endpoint in CDK?


I want to pass the IoT custom endpoint as an env var to a lambda declared in CDK.

I'm talking about the IoT custom endpoint that lives here: enter image description here

How do I get it in context of CDK?


Solution

  • You can ref AWS sample code: https://github.com/aws-samples/aws-iot-cqrs-example/blob/master/lib/querycommandcontainers.ts

    const getIoTEndpoint = new customResource.AwsCustomResource(this, 'IoTEndpoint', {
                onCreate: {
                  service: 'Iot',
                  action: 'describeEndpoint',
                  physicalResourceId: customResource.PhysicalResourceId.fromResponse('endpointAddress'),
                  parameters: {
                    "endpointType": "iot:Data-ATS"
                  }
                },
                policy: customResource.AwsCustomResourcePolicy.fromSdkCalls({resources: customResource.AwsCustomResourcePolicy.ANY_RESOURCE})
              });
    
    const IOT_ENDPOINT = getIoTEndpoint.getResponseField('endpointAddress')