Archives

Archives / 2017 / February
  • Ever wonder on which platform Amazon AWS Lambda in C# is running?

    In last December, AWS announced C# support for AWS Lambda using .NET Core 1.0 runtime. Ever wonder on which platform is it running? I am curious too and I did not see it in any official documentation. So I decided to write a small AWS Lambda function to detect the platform:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using Amazon.Lambda.Core;
    using Amazon.Lambda.Serialization;
     
    // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
    [assemblyLambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
     
    namespace SysInfoLambda
    {
        public class Function
        {
     
            /// <summary>
            /// A simple function that takes a string and does a ToUpper
            /// </summary>
            /// <param name="input"></param>
            /// <param name="context"></param>
            /// <returns></returns>
            public RuntimeInfo FunctionHandler(ILambdaContext context)
            {
                return new RuntimeInfo()
                {
                    FrameworkDescription = RuntimeInformation.FrameworkDescription,
                    OSArchitecture = RuntimeInformation.OSArchitecture,
                    ProcessArchitecture = RuntimeInformation.ProcessArchitecture,
                    OSDescription = RuntimeInformation.OSDescription,
                    OSPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OS.Linux :
                        RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OS.OSX : OS.Windows
                };
            }
     
        }
     
        public class RuntimeInfo
        {
            public string FrameworkDescription { getset; }
            public Architecture OSArchitecture { getset; }
            public string OSDescription { getset; }
            public Architecture ProcessArchitecture { getset; }
            public OS OSPlatform { getset; }
        }
     
        public enum OS
        {
            Linux,
            OSX,
            Windows
        }
     
    }
    

    The result? The AWS C# Lambda runs in 64 bit Linux. The extract OS description is: Linux 4.4.35-33.55.amzn1.x86_64 #1 SMP Tue Dec 6 20:30:04 UTC 2016.