Not able to create an SNS application endpoint using lambda function

Viewed 36

In this code, the below method is not working at all. Not event throwing any error, nothing getting printed in the logs. Any suggestion on this?

const response = await snsClient.send(command,(err,data)=>{
});

Complete Code

import { SNSClient, CreatePlatformEndpointCommand } from  "@aws-sdk/client-sns";
const snsClient = new SNSClient({ region: process.env.AWS_REGION });
export  { snsClient };

export const handler = async (event,context) => {
  

var params = {
    PlatformApplicationArn: process.env.SNS_APP_ID, /* required */
    Token: event.DeviceToken, /* required */
    CustomUserData: 'UserId='+ event.ID
  };

try{
        const command = new CreatePlatformEndpointCommand(params);

        const response = await snsClient.send(command,(err,data)=>{
        if (err) 
        { 
            console.log(err, err.stack); // an error occurred
            return;
        }
        else 
        {
            console.log(data);           // successful response
        }
        var endpointArn = response.EndpointArn;
        console.log(response);
        });

    }
    catch (error) {
        console.log(error);
    } finally {
        console.log("completed!");
    }
};
0 Answers
Related