AWS CDK的加密卷和自己的KMS密钥失败

时间:2019-06-13 15:52:18

标签: amazon-web-services amazon-cloudformation aws-kms aws-ebs aws-cdk

我正在尝试使用AWS CDK创建一个EBS卷,该CDK由我自己的C#KMS密钥使用以下代码段加密:

var kmsProps = new EncryptionKeyProps
{
    Description = "Encryption key for Storage",
    EnableKeyRotation = true,
    Enabled = true,
    Retain = true
};

var kms = new EncryptionKey(stack, "kms-storage", kmsProps);

var kmsAlias = kms.AddAlias("alias/" + stack.StackName + "/storage");

var storageVolume = new CfnVolume(stack, "server-storage-encrypted", new CfnVolumeProps
{
    AvailabilityZone = privateSubnet1.AvailabilityZone,
    KmsKeyId = kmsAlias.AliasName,
    Size = 30,
    Encrypted = true,
    Tags = new ICfnTag[]
    {
        new CfnTag {Key = "Name", Value = "Server Storage"}
    },
    VolumeType = "gp2"
}); 

但是deploy命令失败,并显示Volume vol-0e88979f5568c16fa is still creating错误

您是否知道我在KMS政策等方面做错了什么? 试图寻找它,我唯一发现的是自动缩放需要访问密钥,而与EBS / EC2无关。

1 个答案:

答案 0 :(得分:0)

我今天遇到了这个问题。原来在 KmsKeyId 中使用别名导致了这个问题。将别名更改为实际密钥 ID 后,堆栈已成功创建。尽管文档说可以使用别名,它对我不起作用

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-ebs-volume.html