AWSTemplateFormatVersion: '2010-09-09'
Conditions:
  IsProd:
    Fn::Equals:
      - Ref: StageName
      - production
Globals:
  Function:
    Environment:
      Variables:
        TABLE_USER_SESSION:
          Ref: TableUserSession
    Handler: index.handler
    MemorySize: 256
    Runtime: nodejs18.x
    Timeout: 30
    Tracing: Active
Outputs:
  TableUserSession:
    Description: The name of the DynamoDB table for TableUserSession
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-TableUserSession
    Value:
      Ref: TableUserSession
Parameters:
  StageName:
    AllowedValues:
      - development
      - production
      - test
    Default: development
    Description: The name of the stage
    Type: String
Resources:
  TableUserSession:
    Properties:
      AttributeDefinitions:
        - AttributeName: pk
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      KeySchema:
        - AttributeName: pk
          KeyType: HASH
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      SSESpecification:
        SSEEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      Tags:
        - Key: StageName
          Value:
            Ref: StageName
        - Key: TableName
          Value: TableUserSession
      TimeToLiveSpecification:
        AttributeName: ttl
        Enabled: true
    Type: AWS::DynamoDB::Table
Transform: AWS::Serverless-2016-10-31
