【问题标题】:AWS IAM CDK: tagging and creating access key for a userAWS IAM CDK:为用户标记和创建访问密钥
【发布时间】:2019-10-16 21:27:06
【问题描述】:

我正在尝试使用 AWS CDK 通过自定义策略创建具有最小权限的用户,但我坚持标记该用户并创建其访问密钥。

下面是我的代码:

public class Sample extends App {
    public static void main(final String[] args) {
            App app = new App();
            new UserStack(app, "user-stack");
            app.run();
    }

    public static class UserStack extends Stack {
        // Not able to add Tag and Create Access Key
        public UserStack(final App parent, final String name) {
            super(parent, name);

            PolicyStatement statement = new PolicyStatement(PolicyStatementEffect.Allow);
            statement.addResource("*");
            statement.addAction("lambda:UpdateFunctionCode");

            User user = new User(this, "LambdaDeployer", UserProps.builder().withUserName("lambda-deployer").withPath("/").build());
            user.addToPolicy(statement);

            Tag tag = new Tag("Project", "devops");
            // how to tag the user ??

            new CfnOutput(this, "LambdaDeployerOutputAccessKey", CfnOutputProps.builder().withValue("AWS::IAM::AccessKey").build());
            new CfnOutput(this, "LambdaDeployerOutputSecretAccessKey", CfnOutputProps.builder().withValue("AWS::IAM::SecretAccessKey").build());
        }
    }
}

【问题讨论】:

    标签: amazon-iam aws-cdk


    【解决方案1】:

    您可能必须使用Custom Resource 才能调用TagUser API,因为向用户添加标签是not available natively in CloudFormation

    您可以使用 CDK 中的新功能来帮助您创作自定义资源:https://github.com/awslabs/aws-cdk/pull/1850

    【讨论】:

      猜你喜欢
      • 2019-02-08
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 2022-01-12
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多