Last active
October 30, 2022 06:12
-
-
Save tmarshall/6149ed2475f964cda3f5 to your computer and use it in GitHub Desktop.
aws-sdk sns example, in Node.js
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
var AWS = require('aws-sdk'); | |
AWS.config.update({ | |
accessKeyId: '{AWS_KEY}', | |
secretAccessKey: '{AWS_SECRET}', | |
region: '{SNS_REGION}' | |
}); | |
var sns = new AWS.SNS(); | |
sns.createPlatformEndpoint({ | |
PlatformApplicationArn: '{APPLICATION_ARN}', | |
Token: '{DEVICE_TOKEN}' | |
}, function(err, data) { | |
if (err) { | |
console.log(err.stack); | |
return; | |
} | |
var endpointArn = data.EndpointArn; | |
var payload = { | |
default: 'Hello World', | |
APNS: { | |
aps: { | |
alert: 'Hello World', | |
sound: 'default', | |
badge: 1 | |
} | |
} | |
}; | |
// first have to stringify the inner APNS object... | |
payload.APNS = JSON.stringify(payload.APNS); | |
// then have to stringify the entire message payload | |
payload = JSON.stringify(payload); | |
console.log('sending push'); | |
sns.publish({ | |
Message: payload, | |
MessageStructure: 'json', | |
TargetArn: endpointArn | |
}, function(err, data) { | |
if (err) { | |
console.log(err.stack); | |
return; | |
} | |
console.log('push sent'); | |
console.log(data); | |
}); | |
}); |
Oh... Really I received a push notification from code trigger. But too long. maybe random. :( . What happened with Android push with amazon sns
Hm.. weird.
I have to sleep now, but i will try to help u. Here in brazil its late..
Goodnight
Em qua, 8 de jan de 2020 00:32, Huy Le <notifications@github.com> escreveu:
… Oh... Really I received a push notification from code trigger. But too
long. maybe random. :(
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6149ed2475f964cda3f5?email_source=notifications&email_token=AKDCZFMYJTXP6XXS6NVADUTQ4VCOJA5CNFSM4IHYIJGKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF7CU4#gistcomment-3130702>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKDCZFOPMGTLYZI3DGX73WDQ4VCOJANCNFSM4IHYIJGA>
.
Thanks @lucasrleandro. Good night
Friend, is the React front end part correct?
Em qua., 8 de jan. de 2020 às 00:37, Huy Le <notifications@github.com>
escreveu:
… Thanks @lucasrleandro <https://github.com/lucasrleandro>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6149ed2475f964cda3f5?email_source=notifications&email_token=AKDCZFKARY2CLLWAKSCE7LLQ4VC55A5CNFSM4IHYIJGKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF7CVE#gistcomment-3130706>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKDCZFMRLWIXUFVQSYJLVLTQ4VC55ANCNFSM4IHYIJGA>
.
Yes, Lucas. It is working now. Root cause: my android app crash then it will not receive Push Notification.
Thanks
So its solved?
Em qua., 8 de jan. de 2020 às 22:33, Huy Le <notifications@github.com>
escreveu:
… Yes, Lucas. It is working now. Root cause: my android app crash then it
will not receive Push Notification.
Thanks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6149ed2475f964cda3f5?email_source=notifications&email_token=AKDCZFLBHL7EVYCCIARW6GTQ4Z5F7A5CNFSM4IHYIJGKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF7ES4#gistcomment-3131694>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKDCZFIYQUQDYROCYHCUV7DQ4Z5F7ANCNFSM4IHYIJGA>
.
getting this error 'User: arn:aws:iam::***********:user/******* is not authorized to perform: SNS:Publish on resource:'
MessageStructure
seems does not work.
When I add MessageStructure
to publish parameters, it does not send a notification to the subscriber.
Very helpful, thank you
Looks like there is some stuff to add.
The platformEndpointArn can be created but inactive.
I had a lot of trouble with it and currently working on it.
AWS doc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sent push successfully, but not show anything on my device.