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
asked 10 days ago162 views
1 Answer
1
Accepted Answer

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

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

profile pictureAWS
EXPERT
Greg_B
answered 10 days ago
profile picture
EXPERT
reviewed 10 days ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions