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
已提問 24 天前檢視次數 186 次
1 個回答
1
已接受的答案

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

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

profile pictureAWS
專家
Greg_B
已回答 24 天前
profile picture
專家
已審閱 24 天前
  • 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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南