# Reference: https://github.com/aws-samples/sessions-with-aws-sam/blob/master/go-al2/template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Unstable plan analysis function

Resources:
  UnstablePlanFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      FunctionName: JOB_FUNC_NAME_PLACEHOLDER
      CodeUri: ./ # Local path to the function binary
      Handler: bootstrap # Name of the handler function binary
      Runtime: provided.al2 # Runtime listed in: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
      Architectures:
        - x86_64
      Timeout: 600 # in seconds (10 minutes)
      MemorySize: 512 # in MB
      Environment: # More info about Env Vars: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
        Variables:
          OFFSET_HOURS: !Ref OffsetHours
          SECRET_REGION: !Ref SecretRegion
      Role: !FindInMap
        - EnvConfigs
        - Ref: Stage
        - TaskRole
      VpcConfig:
        SecurityGroupIds: !FindInMap
          - EnvConfigs
          - Ref: Stage
          - SecurityGroupIds
        SubnetIds: !FindInMap
          - EnvConfigs
          - Ref: Stage
          - SubnetIds
    Metadata:
      BuildMethod: makefile # More info about BuildMethod: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html

Parameters:
  Stage:
    Type: String
    Default: staging
    Description: Stage is a parameter defined by `sam deploy --parameter-overrides Stage=$SAM_STAGE` command
  OffsetHours:
    Type: Number
    Default: 3
    Description: OffsetHours is a parameter defined by `sam deploy --parameter-overrides OffsetHours=$OFFSET_HOURS` command
  SecretRegion:
    Type: String
    Default: us-west-2

Mappings:
  EnvConfigs:
    staging:
      TaskRole: arn:aws:iam::552185537300:role/ce-task
      SecurityGroupIds:
        - sg-08bb42935021e024b
      SubnetIds:
        - subnet-098de5356152db3c2
        - subnet-07b011c7c70726009
        - subnet-0289b81f1633629b6
    prod:
      TaskRole: arn:aws:iam::557537366020:role/ce-task
      SecurityGroupIds:
        - sg-0118e0f1069a02381
      SubnetIds:
        - subnet-0539a75851b24df03
        - subnet-0258434fb4a0d03ef
        - subnet-007f996591222aec2
        - subnet-068050d69d264d42a
        - subnet-0ed2ca77533d511e4
