/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task <string> FunctionHandler(CodeDeployInvokeRequest input, ILambdaContext context) { String envId = input.EnvironmentId; String appName = input.ApplicationName; AmazonCodeDeployClient client = new AmazonCodeDeployClient(); var request = new CreateDeploymentRequest(); request.ApplicationName = appName; request.DeploymentGroupName = input.DeploymentGroup; request.Description = "Testing Deployment created by Lambda"; request.Revision = new RevisionLocation() { RevisionType = Amazon.CodeDeploy.RevisionLocationType.S3, S3Location = new S3Location() { Bucket = input.S3BucketName, BucketType = Amazon.CodeDeploy.BundleType.Zip, Key = input.S3KeyName } }; var response = await client.CreateDeploymentAsync(request); return(response.ToString()); }
/// <summary> /// Deploys an application revision through the specified deployment group. /// </summary> /// <param name="applicationName">The name of an AWS CodeDeploy application associated with the applicable IAM user or AWS account.</param> /// <param name="deploymentGroup">The name of the deployment group.</param> /// <param name="settings">The <see cref="DeploySettings"/> 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 <bool> CreateDeployment(string applicationName, string deploymentGroup, DeploySettings settings, CancellationToken cancellationToken = default(CancellationToken)) { if (String.IsNullOrEmpty(applicationName)) { throw new ArgumentNullException("applicationName"); } if (String.IsNullOrEmpty(deploymentGroup)) { throw new ArgumentNullException("deploymentGroup"); } // Create Request AmazonCodeDeployClient client = this.CreateClient(settings); CreateDeploymentRequest request = new CreateDeploymentRequest(); request.ApplicationName = applicationName; request.DeploymentGroupName = deploymentGroup; request.Revision = new RevisionLocation() { RevisionType = RevisionLocationType.S3, S3Location = new S3Location() { BundleType = BundleType.Zip, Bucket = settings.S3Bucket, Key = settings.S3Key, Version = settings.S3Version } }; // Check Response CreateDeploymentResponse response = await client.CreateDeploymentAsync(request, cancellationToken); if (response.HttpStatusCode == HttpStatusCode.OK) { _Log.Verbose("Successfully deployed application '{0}'", applicationName); return(true); } else { _Log.Error("Failed to deploy application '{0}'", applicationName); return(false); } }
internal static string Deploy(string applicationName, string deploymentGroupName, string bucket, string key, string eTag, string version, string region = "") { try { S3Location location = new S3Location() { Bucket = bucket, BundleType = BundleType.Zip, ETag = eTag, Key = key, Version = version }; CreateDeploymentRequest request = new CreateDeploymentRequest() { ApplicationName = applicationName, DeploymentGroupName = deploymentGroupName, Revision = new RevisionLocation() { S3Location = location, RevisionType = RevisionLocationType.S3 }, }; AmazonCodeDeployClient client = string.IsNullOrEmpty(region) ? new AmazonCodeDeployClient() : new AmazonCodeDeployClient(RegionEndpoint.GetBySystemName(region)); Task <CreateDeploymentResponse> response = client.CreateDeploymentAsync(request); Task.WaitAll(new Task[] { response }); string message = "Deployment Created: {0} \ndotnet codedeploy status --deployment-id {0}"; if (!string.IsNullOrEmpty(region)) { message += " --region {1}"; } Log.Information(message, response.Result.DeploymentId, region); return(response.Result.DeploymentId); } catch (System.Exception e) { Log.Error($"{e.GetBaseException().GetType().Name}: {e.Message}"); return(null); } }