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
질문됨 한 달 전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
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠