Created
January 17, 2018 15:04
-
-
Save z4o4z/4f158bbcac3de4bfeb247df31970c24e 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
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