Skip to content

Instantly share code, notes, and snippets.

@vuongngo
Created August 22, 2017 10:59
Show Gist options
  • Save vuongngo/9494ffaa03585f2bbca14865f4d0d57a to your computer and use it in GitHub Desktop.
Save vuongngo/9494ffaa03585f2bbca14865f4d0d57a to your computer and use it in GitHub Desktop.
'use strict';
const v4 = require('aws-signature-v4');
const crypto = require('crypto');
exports.handler = (event, context, callback) => {
const url = v4.createPresignedURL(
'GET',
process.env.IOT_ENDPOINT_HOST.toLowerCase(),
'/mqtt',
'iotdevicegateway',
crypto.createHash('sha256').update('', 'utf8').digest('hex'),
{
'key': process.env.IOT_ACCESS_KEY,
'secret': process.env.IOT_SECRET_KEY,
'protocol': 'wss',
'region': process.env.IOT_AWS_REGION,
}
);
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials' : true
},
body: JSON.stringify({ url: url }),
};
callback(null, response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment