Is there any way to update SNS Topic policy through Java SDK?

Viewed 21

I do have an SNS Topic in my AWS account, which I created through Java SDK, hence the policies attached are default policies.

Is there any way to update the policy through java SDK itself?

1 Answers

Yes, you can use the addPermission and removePermission methods with the PermissionRequest.Builder to define the actions/principals

An example code snippet:

AddPermissionRequest addPermissionRequest = new AddPermissionRequest();
addPermissionRequest.setTopicArn("arn:aws:sns:....");
addPermissionRequest.setAWSAccountIds("arn:aws:iam::account:role/role-name-with-path");
addPermissionRequest.setActionNames("sns:Publish", "sns:GetTopicAttributes");

AddPermissionResult addPermissionResult = snsClient.addPermission(addPermissionRequest);
Related