简体   繁体   中英

IAM Role Conditions in AWS CDK Python

I am creating a new IAM Role custom policy, but it do a rollback with the reason: MalformedPolicyDocument


myrole = iam.Role(self,config['CUSTOM_POLICY']['ROLE'],
    assumed_by=iam.ServicePrincipal('ec2.amazonaws.com'),
    role_name=config['CUSTOM_POLICY']['NAME']
)
myrole.add_to_policy(
    iam.PolicyStatement(
        effect=iam.Effect.ALLOW,
        resources=['arn:aws:s3:::MyBucket/*'],
        actions=[
            's3:CreateBucket',
            's3:GetObject',
            's3:ListBucket',
            's3:PutObject'
        ],
        conditions=[
            {
                'aws:SourceIp':'192.10.10.10/32'
            }
        ]
    )
)

If I delete the conditions it works, what is the correct syntax considering conditionals?

It looks like you're leaving out the condition operator . Are you looking for something like:

conditions=[
    {
        "NotIpAddress": {
            "aws:SourceIp": ["192.10.10.10/32"]
        }
        
    }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM