Beispiel #1
0
        static async Task <(string functionArn, string functionName, Func <Task> functionCleanup)> CreateFunction(
            string roleArn,
            IAmazonLambda lambda,
            LambdaCreationOptions options)
        {
            var functionName = $"Beetles_{options.Name}_{options.Timestamp}";

            var retryWait = Stopwatch.StartNew();
            CreateFunctionResponse function = null;

            do
            {
                try
                {
                    function = await lambda.CreateFunctionAsync(new CreateFunctionRequest
                    {
                        Code = new FunctionCode {
                            ZipFile = new MemoryStream(File.ReadAllBytes(options.PackagePath))
                        },
                        Description  = $"Beetles Load Test {options.Name}",
                        FunctionName = functionName,
                        Handler      = options.LambdaHandlerName,
                        MemorySize   = options.MemorySize,
                        Publish      = true,
                        Role         = roleArn,
                        Runtime      = "dotnetcore2.1",
                        Timeout      = 120,
                        Environment  = new Environment
                        {
                            Variables =
                            {
                                [Constants.ConfigurationTypeNameKey] = options.SettingsTypeName
                            }
                        },
                        VpcConfig = new VpcConfig()
                    }, options.CancellationToken);

//          await lambda.PutFunctionConcurrencyAsync(new PutFunctionConcurrencyRequest()
//          {
//            FunctionName = functionName,
//            ReservedConcurrentExecutions = options.ProvisionedConcurrency
//          }, options.CancellationToken);
                }
                catch (InvalidParameterValueException) when(retryWait.Elapsed < TimeSpan.FromMinutes(1))
                {
                }
            } while (function == null);

            var functionArn = function.FunctionArn;

            return(functionArn, functionName, async() => await lambda.DeleteFunctionAsync(functionName));
        }
        protected async Task DeleteFunctionIfExistsAsync(IAmazonLambda lambdaClient)
        {
            var request = new DeleteFunctionRequest
            {
                FunctionName = FunctionName
            };

            try
            {
                var response = await lambdaClient.DeleteFunctionAsync(request);
            }
            catch (ResourceNotFoundException)
            {
                // no problem
            }
        }
Beispiel #3
0
        public static void DeleteCreatedFunctions(IAmazonLambda lambdaClient)
        {
            var deletedFunctions = new List <string>();

            foreach (var function in createdFunctionNames)
            {
                try
                {
                    lambdaClient.DeleteFunctionAsync(function).Wait();
                    deletedFunctions.Add(function);
                }
                catch { }
            }

            foreach (var df in deletedFunctions)
            {
                createdFunctionNames.Remove(df);
            }
        }
Beispiel #4
0
 private Amazon.Lambda.Model.DeleteFunctionResponse CallAWSServiceOperation(IAmazonLambda client, Amazon.Lambda.Model.DeleteFunctionRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Lambda", "DeleteFunction");
     try
     {
         #if DESKTOP
         return(client.DeleteFunction(request));
         #elif CORECLR
         return(client.DeleteFunctionAsync(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;
     }
 }