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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则