AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  IM-CAPITAL-BACKEND-SERVICE 

  SAM Template for IM-CAPITAL-BACKEND-SERVICE

Parameters:
  Environment:
    Type: String
    Default: dev
    AllowedValues:
      - dev
      - prod
    Description: Environment of this stack of resources

    # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Api:
    Cors:
      AllowMethods: "'GET, POST, OPTIONS'"
      AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
      AllowOrigin: "'*'"
    Auth:
      AddDefaultAuthorizerToCorsPreflight: false
  Function:
    Timeout: 30
    MemorySize: 1536
    Runtime: java17
    Architectures:
      - x86_64
    VpcConfig:
      SecurityGroupIds:
        - sg-0089502251d79aa23
      SubnetIds:
        - subnet-08882af1374cdd5d2
        - subnet-0b9b9e77b66be7a4d
    Environment:
      Variables:
        SECRET_NAME: imcapital-dev-mysql-aurora
        REGION: eu-west-1

Resources:
  MyApiGatewayRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - amplify.amazonaws.com
                - apigateway.amazonaws.com
                - lambda.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: ApiGatewayAccess
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - apigateway:*
                Resource: "*"
        - PolicyName: LambdaInvokeAccess
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - lambda:InvokeFunction
                Resource: !GetAtt MyAuthorizer.Arn
  AWSApiGateway:
    Type: AWS::Serverless::Api
    Properties:
      Name: IM-CAPITAL-BACKEND-SERVICE
      StageName: !Sub ${Environment}
      Cors:
        AllowMethods: "'GET, POST, OPTIONS'"
        AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
        AllowOrigin: "'*'"
      Auth:
        Authorizers:
          MyAuthorizer:
            FunctionPayloadType: REQUEST
            FunctionArn: !GetAtt MyAuthorizer.Arn
            FunctionInvokeRole: !GetAtt MyApiGatewayRole.Arn
            Identity:
              Headers:
                - Authorization
        DefaultAuthorizer: MyAuthorizer
#        DefaultAuthorizer:
#          Type: AWS_IAM
#          AuthorizerId:
#            Ref: MyApiGatewayRole
  MyAuthorizer:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "${Environment}-AuthorizerHandler"
      Handler: co.ke.imcapital.handlers.Authorizer::handleRequest
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'

  GetToken:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetToken"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.GetToken::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /gettoken
            Method: get


  TokenCheck:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-TokenCheck"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.TokenCheck::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /tokencheck
            Method: get

  StatementData:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-StatementData"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamStatementData::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /statementdata
            Method: post


        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /statementdata
            Method: options

        IMCAPITALGET:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /statementdata
            Method: get

  SubGroupMembers:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SubGroupMembers"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamSubGroupMembers::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /subgroupmembers
            Method: get

  RequestOTP:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-RequestOTP"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.OTPRequest::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /requestotp
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /requestotp
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /requestotp
            Method: options

  ValidateOTP:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-ValidateOTP"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.ValidateOTP::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /validateotp
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /validateotp
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /validateotp
            Method: options

  AccountBalance:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-AccountBalance"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.AccountBalance::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /accountbalance
            Method: get

  ServiceAgreement:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-ServiceAgreement"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.ServiceAgreement::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /serviceagreement
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /serviceagreement
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /serviceagreement
            Method: options

  ProfileImage:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-ProfileImage"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.ProfileImageRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /profileimage
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /profileimage
            Method: options

  CreateUser:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-CreateUser"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.UserCreation::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createuser
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createuser
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createuser
            Method: options
  GetUser:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetUser"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.UserRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /getuser
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /getuser
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /getuser
            Method: options

  PostTransaction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-PostTransaction"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.Transaction::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /transaction
            Method: post

        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /transaction
            Method: options

        IMCAPITALGET:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /transaction
            Method: get
  PostUpdateTransaction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-PostUpdateTransaction"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.TransactionUpdate::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatetransaction
            Method: post

        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatetransaction
            Method: options

        IMCAPITALGET:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatetransaction
            Method: get
  GetTransactions:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetTransactions"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.TransactionsRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITALGET:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /gettransaction
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /gettransaction
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /gettransaction
            Method: options

  UserToken:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-UserToken"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.UserToken::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /usertoken
            Method: get
  DailyYield:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-DailyYield"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamDailyYield::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /dailyyield
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /dailyyield
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /dailyyield
            Method: options
  
  InitiatePayment:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      Timeout: 45
      FunctionName: !Sub "${Environment}-InitiatePayment"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.InitiatePayment::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /initiatepayment
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /initiatepayment
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /initiatepayment
            Method: options
  Preferred2FA:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-Preferred2FA"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.Preferred2FA::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /preferred2fa
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /preferred2fa
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /preferred2fa
            Method: options
  IMStatement:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-IMStatement"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.IMStatement::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imstatement
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imstatement
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imstatement
            Method: options
  SanlamGetToken:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SanlamGetToken"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamTokenRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamgettoken
            Method: get
  SanlamPurchaseFlow:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SanlamPurchaseFlow"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamPurchaseFlow::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlampurchaseflow
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlampurchaseflow
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlampurchaseflow
            Method: options
  SanlamWithdrawalFlow:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SanlamWithdrawalFlow"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamWithdrawalFlow::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwithdrawalflow
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwithdrawalflow
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwithdrawalflow
            Method: options
  GetSanlamMembers:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetSanlamMembers"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamMembers::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api
          Properties:
            Path: /getsanlammembers
            Method: get
            RestApiId: !Ref AWSApiGateway
        IMCAPITALPOST:
          Type: Api
          Properties:
            Path: /getsanlammembers
            Method: post
            RestApiId: !Ref AWSApiGateway
        IMCAPITALOPTIONS:
          Type: Api
          Properties:
            Path: /getsanlammembers
            Method: options
            RestApiId: !Ref AWSApiGateway

  GetSanlamWithdrawalCharges:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SanlamWithdrawalCharges"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamWithdrawalCharges::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwitdrawalcharge
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwitdrawalcharge
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamwitdrawalcharge
            Method: options
  GetSanlamAccountBalance:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetSanlamAccountBalance"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SanlamAccountBalance::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamaccountbalance
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamaccountbalance
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /sanlamaccountbalance
            Method: options
  IMGetCustomer:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-IMGetCustomer"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.IMCustomerRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetcustomer
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetcustomer
            Method: post

        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetcustomer
            Method: options
  IMAccess:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-IMAccess"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.IMAccess::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imaccess
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imaccess
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imaccess
            Method: options
  LogError:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-LogError"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.ErrorLogger::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /logerror
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /logerror
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /logerror
            Method: options
  WriteLogs:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-WriteS3Logs"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.WriteS3Logs::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
  #      Events:
  #        ScheduleEvent:
  #          Type: Schedule
  #          Properties:
  #            Schedule: rate(1 hour)
  CheckWhiteList:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-CheckWhiteList"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.WhiteListChecker::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /checkwhitelist
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /checkwhitelist
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /checkwhitelist
            Method: options
  GetSettings:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-GetSettings"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SettingRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /getsettings
            Method: get
  CreateSession:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-CreateSession"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SessionCreation::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createsession
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createsession
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /createsession
            Method: options
  UpdateSession:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-UpdateSession"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SessionUpdate::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatesession
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatesession
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /updatesession
            Method: options
  LogS3Error:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-LogS3Error"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.ErrorLoggerS3::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
  SQSLogToFile:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-SQSLogToFile"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.SQSLogToFile::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        ScheduleEvent:
          Type: Schedule
          Properties:
            Schedule: rate(1 hour)

  IMGetAccounts:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: !Sub "${Environment}-IMGetAccounts"
      CodeUri: IM-CAPITAL-BACKEND-SERVICE
      Handler: co.ke.imcapital.handlers.IMAccountsRetrieval::handleRequest
      Role: arn:aws:iam::597707462019:role/IMCapital_serverless_deployment
      Policies:
        - Statement:
            Effect: Allow
            Action:
              - ec2:DescribeNetworkInterfaces
              - ec2:CreateNetworkInterface
              - ec2:DeleteNetworkInterface
              - ec2:DescribeInstances
              - ec2:AttachNetworkInterface
            Resource: '*'
      Events:
        IMCAPITAL:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetaccounts
            Method: get
        IMCAPITALPOST:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetaccounts
            Method: post
        IMCAPITALOPTIONS:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            RestApiId: !Ref AWSApiGateway
            Path: /imgetaccounts
            Method: options



  #  ApplicationResourceGroup:
  #    Type: AWS::ResourceGroups::Group
  #    Properties:
  #      Name:
  #        !Sub ApplicationInsights-SAM-${AWS::StackName}
  #      ResourceQuery:
  #        Type: CLOUDFORMATION_STACK_1_0
  #  ApplicationInsightsMonitoring:
  #    Type: AWS::ApplicationInsights::Application
  #    Properties:
  #      ResourceGroupName:
  #        Ref: ApplicationResourceGroup
  #      AutoConfigurationEnabled: 'true'
  #Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
#  HelloWorldApi:
#    Description: API Gateway endpoint URL for Prod stage for
#    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
#  HelloWorldFunction:
#    Description: Hello World Lambda Function ARN
#    Value: !GetAtt HelloWorldFunction.Arn
#  HelloWorldFunctionIamRole:
#    Description: Implicit IAM Role created for Hello World function
#    Value: !GetAtt HelloWorldFunctionRole.Arn
