简体   繁体   English

CloudFormation - 无法创建 KMS

[英]CloudFormation - Not able to create KMS

I am trying to create a KMS Key using Cloudformation unfortunately I am not able to create it.我正在尝试使用 Cloudformation 创建 KMS 密钥,不幸的是我无法创建它。 In the console I am getting the following error :在控制台中,我收到以下错误:

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

I am not able to understand the root cause of the issue.我无法理解问题的根本原因。 Please refer to the attached template which I am using to create the KMS :请参考我用来创建 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: '*'

Your EnableKeyRotation and PendingWindowInDays should be outside of KeyPolicy :您的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

Note, that there could be other issues which are not yet apparent, eg non-existing principles.请注意,可能存在其他尚不明显的问题,例如不存在的原则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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