[英]How do I create an IAM Principal for an account using AWS CDK for Java?
I want to create a policy that looks like this (which will permit cross account access to a SNS topic):我想创建一个看起来像这样的策略(这将允许跨帐户访问 SNS 主题):
{
"Statement":[{
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":"sns:Subscribe",
"Resource":"arn:aws:sns:us-east-2:123456789012:MyTopic"
}]
}
How do I create this using the Java CDK?如何使用 Java CDK 创建它? I think I should be using AccountPrincipal
but I can't find a class that seems relevant that has a public constructor.我想我应该使用AccountPrincipal
但我找不到一个似乎相关且具有公共构造函数的 class。
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()
);
Use AccountRootPrincipal
(which implements IPrincipal
) like below:使用AccountRootPrincipal
(实现IPrincipal
),如下所示:
List.of(new AccountRootPrincipal())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.