예제 #1
0
        /// Creates a mock context from a given Lambda handler and event
        public MockLambdaContext(string handler, string eventBody)
        {
            RequestId       = Guid.NewGuid().ToString();
            StartTime       = DateTime.Now;
            Body            = eventBody;
            Timeout         = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_TIMEOUT", "300"));
            MemorySize      = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "1536"));
            FunctionName    = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_NAME", "test");
            FunctionVersion = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_VERSION", "$LATEST");
            LogGroup        = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_GROUP_NAME", $"/aws/lambda/{FunctionName}");
            LogStream       = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_STREAM_NAME", RandomLogStreamName);
            Region          = EnvHelper.GetOrDefault("AWS_REGION", EnvHelper.GetOrDefault("AWS_DEFAULT_REGION", "us-east-1"));
            AccountId       = EnvHelper.GetOrDefault("AWS_ACCOUNT_ID", "000000000000");
            Arn             = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_INVOKED_ARN", $"arn:aws:lambda:{Region}:{AccountId}:function:{FunctionName}");
            StayOpen        = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOCKER_LAMBDA_STAY_OPEN"));

            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", FunctionName);
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", FunctionVersion);
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", MemorySize.ToString());
            Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_GROUP_NAME", LogGroup);
            Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_STREAM_NAME", LogStream);
            Environment.SetEnvironmentVariable("AWS_REGION", Region);
            Environment.SetEnvironmentVariable("AWS_DEFAULT_REGION", Region);
            Environment.SetEnvironmentVariable("_HANDLER", handler);
        }
예제 #2
0
 /// Gets the function handler from arguments or environment
 static string GetFunctionHandler(string[] args)
 {
     return(args.Length > 0 ? args[0] : EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_HANDLER", string.Empty));
 }
예제 #3
0
 /// Gets the event body from arguments or environment
 static string GetEventBody(string[] args)
 {
     return(args.Length > 1 ? args[1] : EnvHelper.GetOrDefault("AWS_LAMBDA_EVENT_BODY", "{}"));
 }