How to get the AWS IoT custom endpoint in CDK?

Bir*_*sky 3 amazon-web-services aws-cloudformation aws-lambda aws-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: 在此处输入图片说明

How do I get it in context of CDK?

小智 5

您可以参考 AWS 示例代码: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')
Run Code Online (Sandbox Code Playgroud)