Yur*_*ter 2 userprincipal amazon-iam aws-cdk aws-event-bridge
我正在通过 CDK 在 AWS EventBridge 中创建自定义总线:
export class EventbridgeStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const targetCoreBus = new events.EventBus(this, 'TargetCoreBus', {
eventBusName: 'TargetCoreBus',
});
targetCoreBus.grantPutEventsTo(new iam.AccountPrincipal('1234567890'));
}
}
Run Code Online (Sandbox Code Playgroud)
巴士制作得很好,但我假设线路
targetCoreBus.grantPutEventsTo(new iam.AccountPrincipal('1234567890'));
Run Code Online (Sandbox Code Playgroud)
将向总线添加策略,允许指定帐户将事件放入其中。但它似乎没有做任何事情,堆栈中没有合成任何新内容,也没有向总线添加任何策略。这是预期的吗,我做错了什么吗?
grantPutEventsTo向受让人添加内联的、基于身份的策略。例如,targetCoreBus.grantPutEventsTo(MyLambda)将添加 aAWS::IAM::Policy到 Lambda 的执行角色。
您想要将帐户主体添加到总线的基于资源的策略中。CfnEventBusPolicy构造将执行此操作:
new events.CfnEventBusPolicy(this, 'CustomBusResoucePolicy', {
statementId: 'Cross-Account-Bus-20220509',
action: 'events:PutEvents',
principal: '123456789012',
eventBusName: targetCoreBus.eventBusName,
condition: {...},
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1425 次 |
| 最近记录: |