AWSTemplateFormatVersion: "2010-09-09"
Description: DT Lambdas stack
Parameters:
  #------------------------
  # Deployment Information
  #------------------------
  environment:
    Type: String
    Description: Name of the environment
    Default: production
  release:
    Type: String
    Description: Name of the release name of the stack version to use.
    Default: production

  #----------------
  # IAM Information
  #----------------
  TaskManagerRole:
    Type: String
    Description: IAM role assumed by Task Manager Lambda
  VpcId:
    Type: AWS::EC2::VPC::Id
    Description: The id of the VPC the cluster will be in
    ConstraintDescription: VPC Id must begin with 'vpc-'
  SubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
    Description: Comma seperated list of subnets for ECS instances to run in

Resources:

  TaskListSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: TaskListManagerLambda Allowed Ports
      VpcId: !Ref VpcId
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '0'
        ToPort: '65535'
        CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
      - IpProtocol: tcp
        FromPort: '0'
        ToPort: '65535'
        CidrIp: 0.0.0.0/0


  TaskListManagerLambda:
    Type: AWS::Lambda::Function
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.7
      Code:
        S3Bucket: dt-deployment-bucket
        S3Key: !Sub "${release}/lambda/task_queue_manager.zip"
      FunctionName: !Sub "FnQueueManager-DT-${environment}"
      Description: Adds and removes tasks from a redis list
      MemorySize: 128
      Timeout: 10
      Role: !Ref TaskManagerRole
      VpcConfig:
        SecurityGroupIds:
        - !Ref TaskListSecurityGroup
        SubnetIds: !Ref SubnetIds

Outputs:
  TaskListManager:
    Value: !GetAtt TaskListManagerLambda.Arn
    Description: Function that adds and removes tasks from a redis list