示例#1
0
        public void LambdaGetFunctionConfiguration()
        {
            #region to-retrieve-a-lambda-functions-event-source-mapping-1481661622799

            var response = client.GetFunctionConfiguration(new GetFunctionConfigurationRequest 
            {
                FunctionName = "myFunction",
                Qualifier = "1"
            });

            string codeSha256 = response.CodeSha256;
            long codeSize = response.CodeSize;
            DeadLetterConfig deadLetterConfig = response.DeadLetterConfig;
            string description = response.Description;
            EnvironmentResponse environment = response.Environment;
            string functionArn = response.FunctionArn;
            string functionName = response.FunctionName;
            string handler = response.Handler;
            string kmsKeyArn = response.KMSKeyArn;
            string lastModified = response.LastModified;
            int memorySize = response.MemorySize;
            string role = response.Role;
            string runtime = response.Runtime;
            int timeout = response.Timeout;
            string version = response.Version;
            VpcConfigDetail vpcConfig = response.VpcConfig;

            #endregion
        }
        public void LambdaGetFunctionConfiguration()
        {
            #region to-get-a-lambda-functions-event-source-mapping-1481661622799

            var response = client.GetFunctionConfiguration(new GetFunctionConfigurationRequest
            {
                FunctionName = "my-function",
                Qualifier    = "1"
            });

            string codeSha256  = response.CodeSha256;
            long   codeSize    = response.CodeSize;
            string description = response.Description;
            EnvironmentResponse environment = response.Environment;
            string functionArn                  = response.FunctionArn;
            string functionName                 = response.FunctionName;
            string handler                      = response.Handler;
            string kmsKeyArn                    = response.KMSKeyArn;
            string lastModified                 = response.LastModified;
            string lastUpdateStatus             = response.LastUpdateStatus;
            int    memorySize                   = response.MemorySize;
            string revisionId                   = response.RevisionId;
            string role                         = response.Role;
            string runtime                      = response.Runtime;
            string state                        = response.State;
            int    timeout                      = response.Timeout;
            TracingConfigResponse tracingConfig = response.TracingConfig;
            string version                      = response.Version;

            #endregion
        }
 private Amazon.Lambda.Model.GetFunctionConfigurationResponse CallAWSServiceOperation(IAmazonLambda client, Amazon.Lambda.Model.GetFunctionConfigurationRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Lambda", "GetFunctionConfiguration");
     try
     {
         #if DESKTOP
         return(client.GetFunctionConfiguration(request));
         #elif CORECLR
         return(client.GetFunctionConfigurationAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
示例#4
0
        public void LambdaFunctionTest()
        {
            const string HELLO_SCRIPT =
                @"console.log('Loading http')
 
exports.handler = function (request, response) {
    response.write(""Hello, world!"");
    response.end();
    console.log(""Request completed"");
}";
            MemoryStream stream = new MemoryStream();

            using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
            {
                var entry = archive.CreateEntry("helloworld.js");
                using (var entryStream = entry.Open())
                    using (var writer = new StreamWriter(entryStream))
                    {
                        writer.Write(HELLO_SCRIPT);
                    }
            }
            stream.Position = 0;

            var  functionName = "HelloWorld";
            bool uploaded     = false;

            var  iamRoleName    = "Lambda-" + DateTime.Now.Ticks;
            bool iamRoleCreated = false;

            try
            {
                var iamCreateResponse = iamClient.CreateRole(new CreateRoleRequest
                {
                    RoleName = iamRoleName,
                    AssumeRolePolicyDocument = LAMBDA_ASSUME_ROLE_POLICY
                });

                var statement = new Statement(Statement.StatementEffect.Allow);
                statement.Actions.Add(S3ActionIdentifiers.PutObject);
                statement.Actions.Add(S3ActionIdentifiers.GetObject);
                statement.Resources.Add(new Resource("*"));


                var policy = new Policy();
                policy.Statements.Add(statement);

                iamClient.PutRolePolicy(new PutRolePolicyRequest
                {
                    RoleName       = iamRoleName,
                    PolicyName     = "admin",
                    PolicyDocument = policy.ToJson()
                });

                // Wait for the role and policy to propagate
                Thread.Sleep(5000);

                var uploadRequest = new UploadFunctionRequest
                {
                    FunctionName = functionName,
                    FunctionZip  = stream,
                    Handler      = "helloworld.handler",
                    Mode         = Mode.Event,
                    Runtime      = Runtime.Nodejs,
                    Role         = iamCreateResponse.Role.Arn
                };

                var uploadResponse = lambdaClient.UploadFunction(uploadRequest);
                uploaded = true;
                Assert.IsTrue(uploadResponse.CodeSize > 0);
                Assert.IsNotNull(uploadResponse.ConfigurationId);

                // List all the functions and make sure the newly uploaded function is in the collection
                var listResponse = lambdaClient.ListFunctions();
                var function     = listResponse.Functions.FirstOrDefault(x => x.FunctionName == functionName);
                Assert.IsNotNull(function);
                Assert.AreEqual("helloworld.handler", function.Handler);
                Assert.AreEqual(iamCreateResponse.Role.Arn, function.Role);

                // Get the function with a presigned URL to the uploaded code
                var getFunctionResponse = lambdaClient.GetFunction(functionName);
                Assert.AreEqual("helloworld.handler", getFunctionResponse.Configuration.Handler);
                Assert.IsNotNull(getFunctionResponse.Code.Location);

                // Get the function's configuration only
                var getFunctionConfiguration = lambdaClient.GetFunctionConfiguration(functionName);
                Assert.AreEqual("helloworld.handler", getFunctionConfiguration.Handler);

                // Call the function
                var invokeResponse = lambdaClient.InvokeAsync(functionName);
                Assert.AreEqual(invokeResponse.Status, 202); // Status Code Accepted
            }
            finally
            {
                if (uploaded)
                {
                    lambdaClient.DeleteFunction(functionName);
                }

                if (iamRoleCreated)
                {
                    iamClient.DeleteRole(new DeleteRoleRequest {
                        RoleName = iamRoleName
                    });
                }
            }
        }