internal static async Task <UpdateFunctionCodeResponse> UpdateFunctionCodeAsync
        (
            this AmazonLambdaClient client,
            AppPackage package,

            ASPNetServerLessPublishAWSLambdaConfigSection lambdaConfig,
            CancellationToken cancellationToken = default(CancellationToken)
        )
        {
            var response = (UpdateFunctionCodeResponse)null;

            using (var packageStream = new MemoryStream(package.PackageBytes))
            {
                var updateCodeRequest = new UpdateFunctionCodeRequest()
                {
                    FunctionName = lambdaConfig.FunctionName,
                    ZipFile      = packageStream
                };

                response = await client.UpdateFunctionCodeAsync(updateCodeRequest, cancellationToken).ConfigureAwait(false);

                updateCodeRequest = null;
            }

            return(response);
        }
示例#2
0
        public async Task <string> UpdateFunction(string functionName, string s3Bucket, string s3Key)
        {
            var request = new UpdateFunctionCodeRequest()
            {
                FunctionName = functionName,
                S3Bucket     = s3Bucket,
                S3Key        = s3Key
            };
            var response = await client.UpdateFunctionCodeAsync(request);

            return(response.Description.Trim());
        }
示例#3
0
        /// <summary>
        /// Updates the AWS Lambda functions code.
        /// </summary>
        /// <param name="functionName">The name of an AWS Lambda function.</param>
        /// <param name="settings">The <see cref="UpdateFunctionCodeSettings"/> used during the request to AWS.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <string> UpdateFunctionCode(string functionName, UpdateFunctionCodeSettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(functionName))
            {
                throw new ArgumentNullException(nameof(functionName));
            }



            // Create Request
            AmazonLambdaClient client = this.CreateClient(settings);

            UpdateFunctionCodeRequest request = new UpdateFunctionCodeRequest()
            {
                FunctionName = functionName,

                Publish = settings.Publish,
                DryRun  = settings.DryRun,

                S3Bucket        = settings.S3Bucket,
                S3Key           = settings.S3Key,
                S3ObjectVersion = settings.S3Version,

                ZipFile = settings.ZipFile
            };

            if (settings.ZipPath != null)
            {
                request.ZipFile = this.GetFileStream(settings.ZipPath, settings);
            }



            // Check Response
            UpdateFunctionCodeResponse response = await client.UpdateFunctionCodeAsync(request, cancellationToken);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Successfully updated function '{0}'", functionName);
                return(response.Version);
            }
            else
            {
                _Log.Error("Failed to update function '{0}'", functionName);
                return("");
            }
        }