【发布时间】:2020-07-01 07:28:26
【问题描述】:
我在账户 A 中运行 EC2 实例,并且在账户 A 和 B 中有 SQS 队列。我的应用程序在账户 A 的 EC2 实例上运行。消息侦听器正在获取 queueUrl 并轮询来自可能在账户 A 中的队列的消息或 B。这里是获取 queueUrl 的代码示例,如果我们获取账户 A 的 queueUrl,它可以正常工作,但如果我们提供账户 B sqs queue 作为输入参数,则会失败:
public String getQueueUrl(String queueOwnerAccountId, String region, String queueName) throws AwsException {
try {
AmazonSQS sqs = AmazonSQSClientBuilder.standard().withRegion(Regions.fromName(region)).build();
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName).withQueueOwnerAWSAccountId(queueOwnerAccountId);
GetQueueUrlResult result = sqs.getQueueUrl(getQueueUrlRequest);
return result.getQueueUrl();
} catch (QueueDoesNotExistException e) {
throwAwsException("With accountId:"+queueOwnerAccountId+" ,Queue: "+queueName+" does not exists in region: "+region);
} catch (AmazonClientException e) {
throwAwsException("Invalid destination address:"+e.getMessage());
}
return null;
}
我已为账户 A 中的两个账户队列的 IAM 角色添加了策略(策略具有两个账户的队列的 ARN)。如果我缺少任何设置,请告诉我。谢谢。
【问题讨论】:
-
您是否在账户 B 的 SQS 队列上添加了 Amazon SQS 策略?请参阅:Basic Examples of Amazon SQS Policies - Amazon Simple Queue Service 默认情况下,A 账户无法授予 B 账户权限(否则您可以接管其他人的账户!)。但是,Amazon SQS 能够将策略添加到允许从另一个账户访问的特定队列(很像 Amazon S3 存储桶策略)。
标签: amazon-ec2 amazon-sqs aws-java-sdk