AWSTemplateFormatVersion: '2010-09-09'
Conditions:
  IsProd:
    Fn::Equals:
      - Ref: StageName
      - production
Globals:
  Function:
    Environment:
      Variables:
        TABLE_USER_LOGIN:
          Ref: TableUserLogin
    Handler: index.handler
    MemorySize: 512
    Runtime: nodejs18.x
    Timeout: 30
    Tracing: Active
Outputs:
  TableUserLogin:
    Description: The name of the DynamoDB table for TableUserLogin
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-TableUserLogin
    Value:
      Ref: TableUserLogin
Parameters:
  StageName:
    AllowedValues:
      - development
      - production
      - test
    Default: development
    Description: The name of the stage
    Type: String
Resources:
  SampleSqsQueue:
    Type: AWS::SQS::Queue
  TableUserLogin:
    Properties:
      AttributeDefinitions:
        - AttributeName: pk
          AttributeType: S
        - AttributeName: sk
          AttributeType: S
        - AttributeName: gsi1pk
          AttributeType: S
        - AttributeName: gsi1sk
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      GlobalSecondaryIndexes:
        - IndexName: gsi1
          KeySchema:
            - AttributeName: gsi1pk
              KeyType: HASH
            - AttributeName: gsi1sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      KeySchema:
        - AttributeName: pk
          KeyType: HASH
        - AttributeName: sk
          KeyType: RANGE
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      SSESpecification:
        SSEEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      Tags:
        - Key: StageName
          Value:
            Ref: StageName
        - Key: TableName
          Value: TableUserLogin
    Type: AWS::DynamoDB::Table
Transform: AWS::Serverless-2016-10-31
