Using javascript runtime 20 with IoTDataPlaneClient giving Invalid URL error

0

I have been using a simple Lambda function for testing IoT Core for LoRaWAN gateways and devices, and this has been working fine with javascript runtime 16. I am trying to port the function to javascript runtime 20, so I'm moving from the AWS.IoTData.publish function to the IoTDataPlaneClient.send function.

The send function is resulting in an invalid URL error. This is the relevant code (I have confirmed that xxxxxxxxxxxxxx is actually the correct value, so the specified endpoint URL should be correct):

import { IoTDataPlaneClient, PublishCommand } from "@aws-sdk/client-iot-data-plane";
export const handler = async (event, context) => {
    const client = new IoTDataPlaneClient({ endpoint: 'xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com' });

...

const publishCommand = new PublishCommand({
    topic: event.WirelessMetadata.LoRaWAN.DevEui.concat("/SensorData"),
    payload: JSON.stringify(params),
    qos: 0,
});

try {
    const response = await client.send(publishCommand);
    console.log(response);
} catch (error) {
    console.error(error);
}

The function is running and I see log output from statements preceding the client.send call. This is the error information:

2024-04-26T03:46:31.909Z	0c227226-637f-4551-a01d-6b260517dc89	ERROR	TypeError: Invalid URL
at new URL (node:internal/url:796:36)
at parseUrl (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/url-parser/dist-cjs/index.js:29:21)
at toEndpointV1 (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:112:41)
at customEndpointProvider (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:232:65) {
code: 'ERR_INVALID_URL',
input: 'xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com'

}

The line from the earlier function running under runtime 16 worked fine with the same endpoint specification:

var iotdata = new AWS.IotData({ 'xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com' });

...followed by an iotdata.publish call.

I have looked through the associated permissions and am not seeing anything missing, though I could certainly be overlooking something.

Any direction on where to look to get past this issue would be appreciated.

tkobet
質問済み 1ヶ月前191ビュー
1回答
1
承認された回答

Hi. I think you need the https:// prefix.

https://github.com/aws/aws-sdk-js-v3/issues/4542

profile pictureAWS
エキスパート
Greg_B
回答済み 1ヶ月前
profile picture
エキスパート
レビュー済み 1ヶ月前
  • You know...I ran across something earlier today that said to make sure you have the right protocol specified, and blew right past it. Looking for something more complicated I guess. I made that change and the error is resolved. Thanks very much.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ