I'm trying to create SNS platform application and enable delivery status feature for it by using AWS SDK (Java). As a first step I create necessary roles "SNSSuccessFeedback" and "SNSFailureFeedback". Sample code (Groovy):
AmazonIdentityManagementClient aimClient = getAimClient(/*credentials*/)
// create "SNSSuccessFeedback" role:
aimClient.createRole(new CreateRoleRequest().withRoleName("SNSSuccessFeedback")
.withAssumeRolePolicyDocument('{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"sts:AssumeRole"}]}'))
aimClient.putRolePolicy(new PutRolePolicyRequest().withRoleName("SNSSuccessFeedback")
.withPolicyName("oneClick_SNSSuccessFeedback_1234567890")
.withPolicyDocument('{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents","logs:PutMetricFilter","logs:PutRetentionPolicy"],"Resource":["*"]}]}'))
// the same code for "SNSFailureFeedback" role
// get ARN for both "SNSSuccessFeedback" and "SNSFailureFeedback"
// create platform application:
AmazonSNSClient snsClient = getSnsClient(/*credentials*/)
snsClient.createPlatformApplication(new CreatePlatformApplicationRequest()
.withName("myapp")
.withPlatform("APNS")
.withAttributes([PlatformPrincipal: "certificate", PlatformCredential: "key",
SuccessFeedbackRoleArn: successRoleArn, FailureFeedbackRoleArn: failureRoleArn,
SuccessFeedbackSampleRate: "100"]))
But for some reason I get error:
Invalid parameter: Attributes Reason: Invalid value for attribute: FailureFeedbackRoleArn: arn:aws:iam::1234567890:role/SNSFailureFeedback is not a valid role to allow SNS to write to Cloudwatch Logs (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: c1dbd591-f044-584a-bbac-85fa9a0cbe8d)
If I just add delay (e.g. Thread.sleep(5000)) after roles creation and before platform application creation, then platform application will be created successfully without error.
So, what is a proper way to create roles and platform application with delivery status enabled?