コード例 #1
0
        public async Task TestMultiStageBuildWithSupportLibrary()
        {
            var assembly = this.GetType().GetTypeInfo().Assembly;

            var toolLogger = new TestToolLogger(_testOutputHelper);

            var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/MultiStageBuildWithClassLibraries/TheFunction");

            var functionName = "test-multistage-with-support-library-" + DateTime.Now.Ticks;

            var command = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);

            command.FunctionName = functionName;
            command.Region       = TEST_REGION;
            command.Role         = await TestHelper.GetTestRoleArnAsync();

            command.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:multistagetest";
            command.DisableInteractive = true;

            var created = await command.ExecuteAsync();

            try
            {
                Assert.True(created);

                toolLogger.ClearBuffer();


                var invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
                invokeCommand.FunctionName = command.FunctionName;
                invokeCommand.Region       = TEST_REGION;

                await invokeCommand.ExecuteAsync();

                Assert.Contains("Hello from support library", toolLogger.Buffer);
            }
            finally
            {
                if (created)
                {
                    await command.LambdaClient.DeleteFunctionAsync(command.FunctionName);
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    PrintUsage();
                    Environment.Exit(-1);
                }

                ICommand command = null;
                switch (args[0])
                {
                case DeployFunctionCommand.COMMAND_DEPLOY_NAME:
                    command = new DeployFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case InvokeFunctionCommand.COMMAND_NAME:
                    command = new InvokeFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case ListFunctionCommand.COMMAND_NAME:
                    command = new ListFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case DeleteFunctionCommand.COMMAND_NAME:
                    command = new DeleteFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case GetFunctionConfigCommand.COMMAND_NAME:
                    command = new GetFunctionConfigCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case UpdateFunctionConfigCommand.COMMAND_NAME:
                    command = new UpdateFunctionConfigCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case DeployServerlessCommand.COMMAND_NAME:
                    command = new DeployServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case ListServerlessCommand.COMMAND_NAME:
                    command = new ListServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case DeleteServerlessCommand.COMMAND_NAME:
                    command = new DeleteServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case PackageCommand.COMMAND_NAME:
                    command = new PackageCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    break;

                case "--help":
                case "--h":
                case "help":
                    PrintUsageHeader();

                    if (args.Length > 1)
                    {
                        PrintUsage(args[1]);
                    }
                    else
                    {
                        PrintUsage();
                    }
                    break;

                default:
                    Console.Error.WriteLine($"Unknown command {args[0]}");
                    PrintUsage();
                    Environment.Exit(-1);
                    break;
                }

                if (command != null)
                {
                    command.EnableInteractive = true;
                    var success = command.ExecuteAsync().Result;
                    if (!success)
                    {
                        Environment.Exit(-1);
                    }
                }
            }
            catch (LambdaToolsException e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(-1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Unknown error: {e.Message}");
                Console.Error.WriteLine(e.StackTrace);

                Environment.Exit(-1);
            }
        }
コード例 #3
0
        public async Task PackageFunctionAsLocalImageThenDeployWithDifferentECRTag()
        {
            var assembly = this.GetType().GetTypeInfo().Assembly;

            var toolLogger = new TestToolLogger(_testOutputHelper);

            var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/TestSimpleImageProject");

            var packageCommand = new PackageCommand(toolLogger, fullPath, new string[0]);

            packageCommand.Region             = TEST_REGION;
            packageCommand.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags1";
            packageCommand.DisableInteractive = true;
            packageCommand.PackageType        = "image";

            var packageSuccess = await packageCommand.ExecuteAsync();

            Assert.True(packageSuccess);

            Assert.Contains($"Packaged project as image: \"{packageCommand.DockerImageTag}\"", toolLogger.Buffer);
            Assert.DoesNotContain("Pushing image to ECR repository", toolLogger.Buffer);

            var functionName = "test-package-then-deploy-differenttags-" + DateTime.Now.Ticks;

            toolLogger.ClearBuffer();
            var deployCommand = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);

            deployCommand.FunctionName = functionName;
            deployCommand.Region       = TEST_REGION;
            deployCommand.Role         = await TestHelper.GetTestRoleArnAsync();

            deployCommand.LocalDockerImage   = packageCommand.DockerImageTag;
            deployCommand.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags2";
            deployCommand.DisableInteractive = true;

            var deploySuccess = await deployCommand.ExecuteAsync();

            try
            {
                Assert.True(deploySuccess);
                Assert.DoesNotContain("docker build", toolLogger.Buffer);
                Assert.Contains($"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags2 Push Complete.", toolLogger.Buffer);

                toolLogger.ClearBuffer();
                var invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
                invokeCommand.FunctionName = deployCommand.FunctionName;
                invokeCommand.Payload      = "hello world";
                invokeCommand.Region       = TEST_REGION;

                await invokeCommand.ExecuteAsync();

                // Make sure waiting works.
                Assert.Contains("... Waiting", toolLogger.Buffer);
                Assert.Contains("HELLO WORLD", toolLogger.Buffer);
            }
            finally
            {
                if (deploySuccess)
                {
                    await deployCommand.LambdaClient.DeleteFunctionAsync(deployCommand.FunctionName);
                }
            }
        }
コード例 #4
0
        public async Task TestSimpleImageProjectTest()
        {
            var assembly = this.GetType().GetTypeInfo().Assembly;

            var toolLogger = new TestToolLogger(_testOutputHelper);

            var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/TestSimpleImageProject");

            var functionName = "test-simple-image-project-" + DateTime.Now.Ticks;

            var command = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);

            command.FunctionName = functionName;
            command.Region       = TEST_REGION;
            command.Role         = await TestHelper.GetTestRoleArnAsync();

            command.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:simpleimageproject1";
            command.DisableInteractive = true;

            var created = await command.ExecuteAsync();

            try
            {
                Assert.True(created);

                toolLogger.ClearBuffer();


                var invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
                invokeCommand.FunctionName = command.FunctionName;
                invokeCommand.Payload      = "hello world";
                invokeCommand.Region       = TEST_REGION;

                await invokeCommand.ExecuteAsync();

                // Make sure waiting works.
                Assert.Contains("... Waiting", toolLogger.Buffer);
                Assert.Contains("HELLO WORLD", toolLogger.Buffer);


                // Update function without changing settings.
                toolLogger.ClearBuffer();
                var updateCommand = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);
                updateCommand.FunctionName       = functionName;
                updateCommand.DisableInteractive = true;
                updateCommand.Region             = TEST_REGION;
                updateCommand.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:simpleimageproject1";

                var updated = await updateCommand.ExecuteAsync();

                Assert.True(updated);

                Assert.DoesNotContain("... Waiting", toolLogger.Buffer);

                toolLogger.ClearBuffer();
                invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
                invokeCommand.FunctionName = command.FunctionName;
                invokeCommand.Payload      = "hello world";
                invokeCommand.Region       = TEST_REGION;
                await invokeCommand.ExecuteAsync();

                Assert.Contains("HELLO WORLD", toolLogger.Buffer);



                // Update function with changed settings.
                toolLogger.ClearBuffer();
                updateCommand = new DeployFunctionCommand(toolLogger, fullPath, new string[0]);
                updateCommand.FunctionName       = functionName;
                updateCommand.MemorySize         = 1024;
                updateCommand.DockerImageTag     = $"{TEST_ECR_REPOSITORY}:simpleimageproject1";
                updateCommand.Region             = TEST_REGION;
                updateCommand.DisableInteractive = true;

                updated = await updateCommand.ExecuteAsync();

                Assert.True(updated);
                Assert.Contains("... Waiting", toolLogger.Buffer);


                toolLogger.ClearBuffer();
                invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]);
                invokeCommand.FunctionName = command.FunctionName;
                invokeCommand.Payload      = "hello world";
                invokeCommand.Region       = TEST_REGION;
                await invokeCommand.ExecuteAsync();

                Assert.Contains("HELLO WORLD", toolLogger.Buffer);
            }
            finally
            {
                if (created)
                {
                    try
                    {
                        await command.LambdaClient.DeleteFunctionAsync(command.FunctionName);
                    }
                    catch { }
                }
            }
        }