Parameters:
  EnvironmentName:
    Description: An environment name that is prefixed to resource names
    Type: String
    Default: "wsi"

Resources:
  LambdaIAMRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub ${EnvironmentName}-lambda-role
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Principal:
              Service:
                - "lambda.amazonaws.com"
            Action:
              - "sts:AssumeRole"
      Path: "/"
      ManagedPolicyArns:
        - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"

  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: !Sub ${EnvironmentName}-function
      Runtime: python3.12
      Architectures:
        - x86_64
      Code:
        ZipFile: !Sub |
          def handler(event, context):
              print("Event: ", event)
              return {
                  "statusCode": 200,
                  "body": "Hello from Lambda!"
              }
      MemorySize: 3008
      Handler: index.handler
      Role: !GetAtt LambdaIAMRole.Arn
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName}-lambda