Skip to content

Instantly share code, notes, and snippets.

@z4o4z
Created January 17, 2018 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4o4z/4f158bbcac3de4bfeb247df31970c24e to your computer and use it in GitHub Desktop.
Save z4o4z/4f158bbcac3de4bfeb247df31970c24e to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
const Promise = require('bluebird');
AWS.config.setPromisesDependency(Promise);
AWS.config.update({
region: 'eu-west-1',
credentials: {
accessKeyId: 'sas',
secretAccessKey: 'sas'
}
});
const appArn = 'arn';
const sns = new AWS.SNS();
function processEndpoints(endpoints) {
const failedEndpoints = endpoints.filter(({ Attributes }) => Attributes.Enabled === 'false');
return Promise.each(failedEndpoints, ({ EndpointArn, Attributes }) => {
console.log(`processing ${EndpointArn} arn`, Object.assign(Attributes, { Enabled: 'true' }));
return sns
.setEndpointAttributes({
EndpointArn,
Attributes: Object.assign(Attributes, { Enabled: 'true' })
})
.promise();
});
}
async function main() {
let res = await sns
.listEndpointsByPlatformApplication({
PlatformApplicationArn: appArn
})
.promise();
await processEndpoints(res.Endpoints);
while (res.NextToken) {
res = await sns
.listEndpointsByPlatformApplication({
PlatformApplicationArn: appArn,
NextToken: res.NextToken
})
.promise();
await processEndpoints(res.Endpoints);
}
console.log('the endpoints was succesfully updated');
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment