0
votes
  1. I'm trying to create DynamoDB table using the cloud formation template, I'm getting the error

"One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: CB468V0TU7G4JM4VKV52H3Q583VV4KQNSO5AEM"

Template:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  oeautomatorteamconfigTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: oeautomator-team-config
      AttributeDefinitions:
        - AttributeName: "active"
          AttributeType: "B"
        - AttributeName: "devResolverGroups"
          AttributeType: "S"
        - AttributeName: "excludeAgingList"
          AttributeType: "B"
        - AttributeName: "excludeNoncontrollableList"
          AttributeType: "B"
        - AttributeName: "excludeReroutedList"
          AttributeType: "B"
        - AttributeName: "fleetId"
          AttributeType: "S"
        - AttributeName: "managerLogin"
          AttributeType: "S"
        - AttributeName: "metricsDashboardLinks"
          AttributeType: "S"
        - AttributeName: "orgName"
          AttributeType: "S"
        - AttributeName: "simFolderId"
          AttributeType: "S"
        - AttributeName: "supportResolverGroups"
          AttributeType: "S"
        - AttributeName: "teamName"
          AttributeType: "S"
      KeySchema:
        - AttributeName: "teamName"
          KeyType: "HASH"
      TimeToLiveSpecification:
        AttributeName: "ExpirationTime"
        Enabled: true
      ProvisionedThroughput:
        ReadCapacityUnits: "5"
        WriteCapacityUnits: "5"
    DependsOn:
      - DynamoDBQueryPolicy
  DynamoDBQueryPolicy:
    Type: "AWS::IAM::Policy"
    Properties:
      PolicyName: DynamoDBQueryPolicy
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Action: "dynamodb:Query"
            Resource: "*"
      Roles:
        - Ref: "oeautomatorteamconfigTableQueryRole"

  oeautomatorteamconfigTableQueryRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "dynamodb.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
  1. How to define the attribute types BOOLEAN, LIST and MAP in a CF template for DynamoDB

Please help me solving this issue.

Thanks in advance.

1
How to define the sortKey in this example - Srikanth Alla
If the current answer solves the issue reported (the errors on deployment), its acceptance would be appreciated. - Marcin

1 Answers

0
votes

Your KeySchema only has teamName. Thus, your AttributeDefinitions can't have anything else then teamName, unless you define local or global secondary indices, or use sort key as well. DynamoDB is schema-less.

So it should be:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  oeautomatorteamconfigTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: oeautomator-team-config
      AttributeDefinitions:
        - AttributeName: "teamName"
          AttributeType: "S"
      KeySchema:
        - AttributeName: "teamName"
          KeyType: "HASH"
      TimeToLiveSpecification:
        AttributeName: "ExpirationTime"
        Enabled: true
      ProvisionedThroughput:
        ReadCapacityUnits: "5"
        WriteCapacityUnits: "5"
    DependsOn:
      - DynamoDBQueryPolicy
  DynamoDBQueryPolicy:
    Type: "AWS::IAM::Policy"
    Properties:
      PolicyName: DynamoDBQueryPolicy
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Action: "dynamodb:Query"
            Resource: "*"
      Roles:
        - Ref: "oeautomatorteamconfigTableQueryRole"

  oeautomatorteamconfigTableQueryRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "dynamodb.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"