我想创建一个类似这样的策略(允许跨帐户访问SNS主题(:
{
"Statement":[{
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":"sns:Subscribe",
"Resource":"arn:aws:sns:us-east-2:123456789012:MyTopic"
}]
}
如何使用Java CDK创建它?我认为我应该使用AccountPrincipal
,但我找不到一个似乎相关的具有公共构造函数的类。
myTopic.addToResourcePolicy(
PolicyStatement.Builder
.create()
.actions(List.of("sns:Subscribe"))
.effect(Effect.ALLOW)
.resources(List.of("arn:aws:sns:us-east-2:123456789012:MyTopic"))
.principals(List.of( ...how do I create a principal here?... ))
.build()
);
使用AccountRootPrincipal
(实现IPrincipal
(,如下所示:
List.of(new AccountRootPrincipal())