Skip to content

Instantly share code, notes, and snippets.

@1xtr
Last active July 15, 2023 14:50
Show Gist options
  • Save 1xtr/812a35eb8bab558cab497a3730de3384 to your computer and use it in GitHub Desktop.
Save 1xtr/812a35eb8bab558cab497a3730de3384 to your computer and use it in GitHub Desktop.
YC IoT message
import axios from 'axios'
import winston from 'winston';
export const logger = winston.createLogger({
format: winston.format.json(),
transports: [new winston.transports.Console()],
});
export const snsClientBuilder = (token) => {
const client = axios.create({
baseURL: `https://iot-broker.api.cloud.yandex.net/iot-broker/v1/brokers/${process.env.BROKER_ID}/publish`,
headers: {
post: {
Authorization: `Bearer ${token}`,
},
},
})
return async (data) => {
const payload = {
topic: 'db-and-user-created',
data: Buffer.from(JSON.stringify(data)).toString('base64'),
}
const response = await client.post('', payload)
logger.info({ message: "response", response })
return true
}
}
import { snsClientBuilder, logger } from './helpers.js'
export const handler = async (event, context) => {
await snsClientBuilder(context.token.access_token)({ accountId: '123456789', clientId: '4c2a6820' })
return {
statusCode: 200,
body: 'Hello World!',
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment