Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
randymxj
/
AWSIoTButtonPOSTtoFirebase.js
Last active
Feb 15, 2017
Star
0
Fork
0
Star
Code
Revisions
2
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Raw
AWSIoTButtonPOSTtoFirebase.js
'use strict'
;
/**
* This is a sample AWS Lambda instance with NodeJS
* Simply sending a POST request to Google Firebase
*/
const
AWS
=
require
(
'aws-sdk'
)
;
/**
* handler is the entry point of the button click
*/
exports
.
handler
=
(
event
,
context
,
callback
)
=>
{
console
.
log
(
'Received event:'
,
event
.
clickType
)
;
var
request
=
require
(
'request'
)
;
// Firebase auth key
var
serverKey
=
"Firebase Server Key"
;
var
clientToken
=
"Client Device Token"
;
var
options
=
{
url
:
'https://fcm.googleapis.com/fcm/send'
,
headers
:
{
'Authorization'
:
'key='
+
serverKey
}
,
json
:
{
"to"
:
clientToken
,
"data"
:
{
deviceId
:
`
${
event
.
serialNumber
}
`
,
deviceName
:
'IoT Button'
,
eventName
:
'Click'
,
value
:
`
${
event
.
clickType
}
,
${
event
.
batteryVoltage
}
`
}
}
}
;
request
.
post
(
options
,
function
optionalCallback
(
err
,
httpResponse
,
body
)
{
if
(
err
)
{
return
callback
(
err
)
;
}
}
)
;
}
;
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.