{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"7.6.26\",\"stackType\":\"function-Lambda\",\"metadata\":{}}",
  "Mappings": {
    "EnvironmentMap": {
      "WebClientUrl": {
        "dev": "https://dev.sizzl.com/",
        "prod": "https://sizzl.com/",
        "stage": "https://stage.sizzl.com/"
      }
    }
  },
  "Parameters": {
    "CloudWatchRule": {
      "Type": "String",
      "Default": "NONE",
      "Description": " Schedule Expression"
    },
    "deploymentBucketName": {
      "Type": "String"
    },
    "env": {
      "Type": "String"
    },
    "s3Key": {
      "Type": "String"
    },
    "apiGraphQLAPIIdOutput": {
      "Type": "String"
    },
    "apiGraphQLAPIEndpointOutput": {
      "Type": "String"
    },
    "apiGraphQLAPIKeyOutput": {
      "Type": "String"
    }
  },
  "Conditions": {
    "ShouldNotCreateEnvResources": {
      "Fn::Equals": [
        {
          "Ref": "env"
        },
        "NONE"
      ]
    }
  },
  "Resources": {
    "LambdaFunction": {
      "Type": "AWS::Lambda::Function",
      "Metadata": {
        "aws:asset:path": "./src",
        "aws:asset:property": "Code"
      },
      "Properties": {
        "Code": {
          "S3Bucket": {
            "Ref": "deploymentBucketName"
          },
          "S3Key": {
            "Ref": "s3Key"
          }
        },
        "Handler": "index.handler",
        "FunctionName": {
          "Fn::If": [
            "ShouldNotCreateEnvResources",
            "videoService",
            {
              "Fn::Join": [
                "",
                [
                  "videoService",
                  "-",
                  {
                    "Ref": "env"
                  }
                ]
              ]
            }
          ]
        },
        "Environment": {
          "Variables": {
            "ENV": {
              "Ref": "env"
            },
            "REGION": {
              "Ref": "AWS::Region"
            },
            "AWSCHANNELPOOLTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:AWSChannelPoolTable:Name"
              }
            },
            "CHANNELTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ChannelTable:Name"
              }
            },
            "VIDEOTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:VideoTable:Name"
              }
            },
            "VIEWERTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ViewerTable:Name"
              }
            },
            "LIBRARYTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:LibraryTable:Name"
              }
            },
            "USERTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:UserTable:Name"
              }
            },
            "SCHEDULETABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ScheduleTable:Name"
              }
            },
            "LIKETABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:LikeTable:Name"
              }
            },
            "FOLLOWTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:FollowTable:Name"
              }
            },
            "TAGTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:TagTable:Name"
              }
            },
            "VIDEOTAGSTABLE": {
              "Fn::ImportValue": {
                "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:VideoTagsTable:Name"
              }
            },
            "GRAPHQLAPIENDPOINTOUTPUT": {
              "Ref": "apiGraphQLAPIEndpointOutput"
            },
            "GRAPHQLAPIKEYOUTPUT": {
              "Ref": "apiGraphQLAPIKeyOutput"
            },
            "WebClientUrl": {
              "Fn::FindInMap": [
                "EnvironmentMap",
                "WebClientUrl",
                {
                  "Ref": "env"
                }
              ]
            },
            "AWS_NODEJS_CONNECTION_REUSE_ENABLED": 1
          }
        },
        "Role": {
          "Fn::GetAtt": [
            "LambdaExecutionRole",
            "Arn"
          ]
        },
        "Runtime": "nodejs14.x",
        "Layers": [],
        "Timeout": 25
      }
    },
    "LambdaExecutionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": {
          "Fn::If": [
            "ShouldNotCreateEnvResources",
            "amplifiedchatappLambdaRole3bfce278",
            {
              "Fn::Join": [
                "",
                [
                  "amplifiedchatappLambdaRole3bfce278",
                  "-",
                  {
                    "Ref": "env"
                  }
                ]
              ]
            }
          ]
        },
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        }
      }
    },
    "lambdaexecutionpolicy": {
      "DependsOn": [
        "LambdaExecutionRole"
      ],
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "lambda-execution-policy",
        "Roles": [
          {
            "Ref": "LambdaExecutionRole"
          }
        ],
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
              ],
              "Resource": {
                "Fn::Sub": [
                  "arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:*",
                  {
                    "region": {
                      "Ref": "AWS::Region"
                    },
                    "account": {
                      "Ref": "AWS::AccountId"
                    },
                    "lambda": {
                      "Ref": "LambdaFunction"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    },
    "AccessDynamoDBApiResourcesPolicy": {
      "DependsOn": [
        "LambdaExecutionRole"
      ],
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "amplify-lambda-execution-policy",
        "Roles": [
          {
            "Ref": "LambdaExecutionRole"
          }
        ],
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "dynamodb:BatchWriteItem",
                "dynamodb:BatchGet*",
                "dynamodb:DescribeStream",
                "dynamodb:DescribeTable",
                "dynamodb:Get*",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:BatchWrite*",
                "dynamodb:CreateTable",
                "dynamodb:Delete*",
                "dynamodb:Update*",
                "dynamodb:PutItem",
                "dynamodb:GetItem"
              ],
              "Resource": [
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:AWSChannelPoolTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}/index/*",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:AWSChannelPoolTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ChannelTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:VideoTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ViewerTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:LibraryTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:UserTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:ScheduleTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:LikeTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:FollowTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:TagTable:Name"
                        }
                      }
                    }
                  ]
                },
                {
                  "Fn::Sub": [
                    "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}",
                    {
                      "tablename": {
                        "Fn::ImportValue": {
                          "Fn::Sub": "${apiGraphQLAPIIdOutput}:GetAtt:VideoTagsTable:Name"
                        }
                      }
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
  },
  "Outputs": {
    "Name": {
      "Value": {
        "Ref": "LambdaFunction"
      }
    },
    "Arn": {
      "Value": {
        "Fn::GetAtt": [
          "LambdaFunction",
          "Arn"
        ]
      }
    },
    "Region": {
      "Value": {
        "Ref": "AWS::Region"
      }
    },
    "LambdaExecutionRole": {
      "Value": {
        "Ref": "LambdaExecutionRole"
      }
    },
    "LambdaExecutionRoleArn": {
      "Value": {
        "Fn::GetAtt": [
          "LambdaExecutionRole",
          "Arn"
        ]
      }
    }
  }
}