amazon-web-services - CloudFormation - 无法创建 KMS

标签 amazon-web-services aws-cloudformation amazon-kms

我正在尝试使用 Cloudformation 创建 KMS key ,遗憾的是我无法创建它。在控制台中我收到以下错误:

null (Service: Kms, Status Code: 400, Request ID: 156b452d-8ffb-5517-9jbc-a6yh6e3a79, Extended Request ID: null)

我无法理解问题的根本原因。请参阅我用来创建 KMS 的随附模板:

AWSTemplateFormatVersion: 2010-09-09
Description: Testing KMS Using CloudFormation
        
Resources:
  KMSEncryption:
    Type: AWS::KMS::Key
    Properties:
      Description: KMS-Key
      KeyPolicy:
        Version: '2012-10-17'
        Id: encryption-key
        EnableKeyRotation: 'True'
        PendingWindowInDays: 7
        Statement:
        - Sid: Enable IAM User Permissions
          Effect: Allow
          Principal:
            AWS:
              Fn::Join:
              - ''
              - - 'arn:aws:iam::'
                - Ref: AWS::AccountId
                - :root
          Action: kms:*
          Resource: '*'
        - Sid: Allow use of the key
          Effect: Allow
          Principal:
            AWS:
              Fn::Join:
              - ''
              - - 'arn:aws:iam::'
                - Ref: AWS::AccountId
                - :role/
                - !Ref KMSLambdaRole
          Action:
          - kms:DescribeKey
          - kms:Encrypt
          - kms:Decrypt
          - kms:ReEncrypt*
          - kms:GenerateDataKey
          - kms:GenerateDataKeyWithoutPlaintext
          Resource: '*'
        - Sid: Allow administration of the key
          Effect: Allow
          Principal:
            AWS: arn:aws:iam::xxxxxxxxx:user/Shiv
          Action:
          - kms:Create*
          - kms:Describe*
          - kms:Enable*
          - kms:List*
          - kms:Put*
          - kms:Update*
          - kms:Revoke*
          - kms:Disable*
          - kms:Get*
          - kms:Delete*
          - kms:ScheduleKeyDeletion
          - kms:CancelKeyDeletion

  EncryptionAlias:
    Type: AWS::KMS::Alias
    Properties:
      AliasName: 'Testing'
      TargetKeyId:
        Ref: KMSEncryption

  KMSLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: 'TestingKMSAccess'
      AssumeRolePolicyDocument:
        Statement:
        - Action: ['sts:AssumeRole']
          Effect: Allow
          Principal:
            Service: [lambda.amazonaws.com]
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/ReadOnlyAccess
      Policies:
        - PolicyName: AWSLambdaBasicExecutionRole
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Sid: SQS
                Action:
                  - 'sqs:SendMessage'
                  - 'sqs:SendMessageBatch'
                Effect: Allow
                Resource: '*'

最佳答案

您的EnableKeyRotationPendingWindowInDays应该在KeyPolicy之外:

Resources:
  KMSEncryption:
    Type: AWS::KMS::Key
    Properties:
      Description: KMS-Key
      EnableKeyRotation: 'True'
      PendingWindowInDays: 7
      KeyPolicy:
        Version: '2012-10-17'
        Id: encryption-key
      # the rest

请注意,可能还有其他尚未明显的问题,例如不存在的原则。

关于amazon-web-services - CloudFormation - 无法创建 KMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64385434/

相关文章:

amazon-web-services - 使用无服务器框架将 Lambda 连接到 Elasticache

amazon-web-services - 默认VPC中不存在该安全组

amazon-ec2 - 如何在自动伸缩组中自动加载 EC2 实例?

amazon-web-services - 使用 CDK diff 来区分管道中包含的资源

java - AWS Java 开发工具包 : Specifying KMS Key Id For EBS

mysql - 无法在没有维护时间的情况下创建同步的新 AWS RDS(mysql) 副本

python - 每天运行 python 脚本的最佳方式是什么?

amazon-web-services - AWS SAM 使用可选的 Transform 进行部署

ansible - 将 Ansible 变量传递到自定义 Ansible 模块

amazon-web-services - 使用 AWS KMS 加密静态数据的目的是什么?