Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bulk re-enable SNS endpoints
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.model.Endpoint;
import com.amazonaws.services.sns.model.ListEndpointsByPlatformApplicationRequest;
import com.amazonaws.services.sns.model.ListEndpointsByPlatformApplicationResult;
import com.amazonaws.services.sns.model.SetEndpointAttributesRequest;
import com.google.common.collect.ImmutableMap;
public class BulkUpdate {
public static void main(String[] args) {
String arn = "SNS Application ARN Here";
Region region = RegionUtils.getRegion("SNS Region Here");
AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials("Access Key Here",
"Access Secret Here"));
sns.setEndpoint("https://" + region.getServiceEndpoint("sns"));
String nextToken = null;
do {
ListEndpointsByPlatformApplicationRequest request = new ListEndpointsByPlatformApplicationRequest();
request.withPlatformApplicationArn(arn);
if (nextToken != null) {
request.withNextToken(nextToken);
}
ListEndpointsByPlatformApplicationResult result = sns.listEndpointsByPlatformApplication(request);
System.out.println("result.getEndpoints().size() = " + result.getEndpoints().size());
for (Endpoint endpoint : result.getEndpoints()) {
System.out.println(endpoint.getAttributes());
if (endpoint.getAttributes().get("Enabled").equals("false")) {
System.err.println("UPDATING ENABLED: " + endpoint.getEndpointArn());
final SetEndpointAttributesRequest setRequest = new SetEndpointAttributesRequest()
.withEndpointArn(endpoint.getEndpointArn())
.withAttributes(ImmutableMap.of("Enabled", "true"));
sns.setEndpointAttributes(setRequest);
}
}
nextToken = result.getNextToken();
} while (nextToken != null);
}
}
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.