Issues porting MFA policy example to the CDK #3128
Labels
@aws-cdk/aws-iam
Related to AWS Identity and Access Management
feature-request
A feature should be added or improved.
management/tracking
Issues that track a subject or multiple issues
I'm submitting a ...
Please tell us about your environment:
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
I needed to use https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_my-sec-creds-self-manage.html in the CDK. I ran into a number of dead ends along the way. Some are known issues, some are new. I figured it would be useful to share this real world example that ties them all together.
Due to #964, there's no straight forward way to express
NotAction
in the CDK. Since I'm using Java, the "hack" one person gave would be more involved.I ended up just putting the example policy in a .json file along with
CfnInclude
like so:My initial inclination was to use
Group.attachInlinePolicy
, but I couldn't figure out how to go from theCfnInclude
to an actualPolicy
object. It feels like there should be a straight forward way to deserialize a CloudFormation template into a CDK object to allow for better interop.Since inline policies weren't going to work for me, I switched to a custom managed policy by prepending the example json with this:
I ran into #2974 trying to use
GroupProps.withManagedPolicyArns
. I thought I might just adaptManagedPolicy.fromAwsManagedPolicyName
like so:That gave me this error though. I'm sure there must be another step I'm not aware of to enable resolution with this code. It wasn't immediately clear from reading through the CDK code and documentation.
What ended up working is something like this:
Incidentally, I think the cast usage makes that a little uglier than it should be. This seems to be caused by
GroupProps
using anObject
/any
whereGroup
usesIManagedPolicy
.The text was updated successfully, but these errors were encountered: