Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当prinicpal是角色arn时,sqs策略属性错误_Java_Amazon Web Services_Permissions_Amazon Sqs - Fatal编程技术网

Java 当prinicpal是角色arn时,sqs策略属性错误

Java 当prinicpal是角色arn时,sqs策略属性错误,java,amazon-web-services,permissions,amazon-sqs,Java,Amazon Web Services,Permissions,Amazon Sqs,在将主体指定为角色arn时,为sqs队列创建策略时遇到错误 这是我的密码 public void addQueuePermission(String queueName) { try { String museBackendRoleArn = "arn:aws:iam::xxxxxxxx:role/yyyyyyyy"; SQSActions[] eventQueueActions = {SQSActions.CreateQueue,

在将主体指定为角色arn时,为sqs队列创建策略时遇到错误

这是我的密码

public void addQueuePermission(String queueName) {
        try {
            String museBackendRoleArn = "arn:aws:iam::xxxxxxxx:role/yyyyyyyy";
            SQSActions[] eventQueueActions = {SQSActions.CreateQueue, SQSActions.ReceiveMessage, SQSActions.SendMessage};

            String queueURL = amazonSQS.getQueueUrl(queueName).getQueueUrl();
            List<String> sqsAttributes = new ArrayList<>();
            sqsAttributes.add("QueueArn");
            Map<String, String> att = amazonSQS.getQueueAttributes(queueURL, sqsAttributes).getAttributes();

            Map<String, String> options = new HashMap<>();
            options.put("Policy", createSQSPolicy(Statement.Effect.Allow, museBackendRoleArn, att.get("QueueArn"),
                    eventQueueActions).toJson());
            amazonSQS.setQueueAttributes(queueURL, options);
        } catch(AmazonServiceException ignore) {
            logger.error(ignore.getMessage());
        }
    }

 public static Policy createSQSPolicy(Statement.Effect effect, String principal, String resourceArn, SQSActions[] sqsActions, String sourceArn) {
        Statement statement = new Statement(effect)
                .withActions(sqsActions)
                .withPrincipals(new Principal(principal))
                .withResources(new Resource(resourceArn));
        return new Policy().withStatements(statement);
    }
public void addQueuePermission(字符串queueName){
试一试{
字符串museBackendRoleArn=“arn:aws:iam::xxxxxxxx:role/yyyyyyyyyy”;
SQSActions[]eventQueueActions={SQSActions.CreateQueue,SQSActions.ReceiveMessage,SQSActions.SendMessage};
字符串queueURL=amazonSQS.getQueueUrl(queueName.getQueueUrl();
List sqsAttributes=new ArrayList();
sqsAttributes.add(“QueueArn”);
Map att=amazonSQS.getQueueAttributes(queueURL,sqsAttributes).getAttributes();
Map options=newhashmap();
options.put(“Policy”、createSQSPolicy(Statement.Effect.Allow、museBackendRoleArn、att.get(“QueueArn”),
eventQueueActions.toJson());
setQueueAttributes(queueURL、选项);
}捕获(AmazonServiceException忽略){
logger.error(ignore.getMessage());
}
}
公共静态策略createSQSPolicy(Statement.Effect Effect、字符串主体、字符串资源arn、SQSActions[]SQSActions、字符串源arn){
语句=新语句(效果)
.带动作(SQS动作)
.有委托人(新委托人(委托人))
.使用资源(新资源(resourceArn));
返回新保单(),包括声明(声明);
}
代码返回400错误,错误消息为“参数策略的值无效”

我通过aws控制台尝试了相同的策略,效果很好。我使用的是aws java sdk版本1.11.59

<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.11.59</version>
</dependency>

亚马逊网站
aws java sdk
1.11.59