[英]aws iam role move from CloudFormation to CDK
I am trying to move this iam role from CloudFormation to AWS CDK.我正在尝试将此 iam 角色从 CloudFormation 移至 AWS CDK。 I cant seem to find any good examples of this in Python.
我似乎在 Python 中找不到任何好的例子。 The Condition is where I am stuck at the moment.
条件是我目前被困的地方。 Has anyone created a role similar to this in Python?
有没有人在 Python 中创建过类似的角色?
CognitoUnAuthorizedRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud": !Ref IdentityPool
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr": unauthenticated
Policies:
- PolicyName: "CognitoAuthorizedPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "cognito-sync:*"
Resource: !Join [ "", [ "arn:aws:cognito-sync:", !Ref "AWS::Region", ":", !Ref "AWS::AccountId", ":identitypool/", !Ref IdentityPool] ]
- Effect: Allow
Action:
- iot:Connect
Resource: !Join [ "", [ "arn:aws:iot:", !Ref "AWS::Region", ":", !Ref "AWS::AccountId", ":client/theme*" ] ]
- Effect: Allow
Action:
- iot:Subscribe
Resource: "*"
- Effect: Allow
Action:
- iot:Receive
Resource: !Join [ "", [ "arn:aws:iot:", !Ref "AWS::Region", ":", !Ref "AWS::AccountId", ":topic/*" ] ]
You should search the method in the lib, eg.您应该在库中搜索该方法,例如。
auth_role = aws_iam.Role(
self,
'ApiGwAuthRole',
assumed_by=aws_iam.ServicePrincipal("apigateway.amazonaws.com")
)
Add policy to a resource向资源添加策略
_sqs.add_to_resource_policy(
statement=aws_iam.PolicyStatement(
effect=aws_iam.Effect.ALLOW,
actions=['sqs:SendMessage'],
resources=[_sqs.queue_arn],
principals=[aws_iam.AnyPrincipal()],
conditions={
"ArnEquals": {"aws:SourceArn": _source.ref}
}
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.