Created
August 22, 2017 10:59
-
-
Save vuongngo/9494ffaa03585f2bbca14865f4d0d57a to your computer and use it in GitHub Desktop.
This file contains 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
'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