Parameters:
  EnvironmentName:
    Description: An environment name that is prefixed to resource names
    Type: String
    Default: "analytics"

Resources:
  KinesisDataStream:
    Type: AWS::Kinesis::Stream
    Properties:
      Name: !Sub ${EnvironmentName}-kinesis
      RetentionPeriodHours: 24
      ShardCount: 1
      StreamModeDetails:
        StreamMode: PROVISIONED
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName}-kinesis

  DynamoDB:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Sub ${EnvironmentName}-dynamodb
      AttributeDefinitions:
        - AttributeName: "name"
          AttributeType: "S"
        - AttributeName: "phone"
          AttributeType: "S"
      KeySchema:
        - AttributeName: "name"
          KeyType: "HASH"
        - AttributeName: "phone"
          KeyType: "RANGE"
      BillingMode: PAY_PER_REQUEST
      KinesisStreamSpecification:
        StreamArn: !GetAtt KinesisDataStream.Arn
      StreamSpecification:
        StreamViewType: NEW_IMAGE

      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName}-dynamodb

Outputs:
  DynamoDB:
    Description: "DynamoDB Table"
    Value: !Ref DynamoDB
    Export:
      Name:
        "Fn::Sub": "${AWS::StackName}-DynamoDB"