Last active
July 15, 2023 14:50
-
-
Save 1xtr/812a35eb8bab558cab497a3730de3384 to your computer and use it in GitHub Desktop.
YC IoT message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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