public void CreateDeployment(string appName, string s3Location, string deploymentGroup) { using (var cdClient = new Amazon.CodeDeploy.AmazonCodeDeployClient(Credentials, Amazon.RegionEndpoint.USEast1)) { var s3 = new S3LocationParser(s3Location); var revLocation = new Amazon.CodeDeploy.Model.RevisionLocation { RevisionType = Amazon.CodeDeploy.RevisionLocationType.S3, S3Location = new Amazon.CodeDeploy.Model.S3Location { Bucket = s3.BucketName, BundleType = Amazon.CodeDeploy.BundleType.Zip, Key = s3.Key } }; var depRequest = new Amazon.CodeDeploy.Model.CreateDeploymentRequest { ApplicationName = appName, DeploymentConfigName = "CodeDeployDefault.OneAtATime", DeploymentGroupName = deploymentGroup, Revision = revLocation }; var depResponse = cdClient.CreateDeployment(depRequest); var x = 0; } }
public void DeployPush(string appName, string s3Location, string sourcePath) { var s3 = new S3LocationParser(s3Location); using (var s3Client = new Amazon.S3.AmazonS3Client(Credentials, Amazon.RegionEndpoint.USEast1)) { var getRequest = new Amazon.S3.Model.GetObjectMetadataRequest { BucketName = s3.BucketName, Key = s3.Key }; try { var getResponse = s3Client.GetObjectMetadata(getRequest); // If we got this far, the file already exists in the S3 bucket, so get out! throw new S3KeyAlreadyExistsException(s3); } catch (AmazonS3Exception ex) { // If we got this far, then it's because the S3 file doesn't exist. // Therefore, it's OK to upload with this key. var zipFileName = s3.FileName; var g = Guid.NewGuid().ToString(); var outputFile = Path.Combine(Path.GetTempPath(), g + ".tmp"); ZipFile.CreateFromDirectory(sourcePath, outputFile); var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), zipFileName); if (File.Exists(zipFile)) File.Delete(zipFile); File.Move(outputFile, zipFile); var putRequest = new Amazon.S3.Model.PutObjectRequest { BucketName = s3.BucketName, FilePath = zipFile, Key = s3.Key }; var putResponse = s3Client.PutObject(putRequest); using (var cdClient = new Amazon.CodeDeploy.AmazonCodeDeployClient(Credentials, Amazon.RegionEndpoint.USEast1)) { var revLocation = new Amazon.CodeDeploy.Model.RevisionLocation { RevisionType = Amazon.CodeDeploy.RevisionLocationType.S3, S3Location = new Amazon.CodeDeploy.Model.S3Location { Bucket = s3.BucketName, BundleType = Amazon.CodeDeploy.BundleType.Zip, Key = s3.Key } }; var regRequest = new Amazon.CodeDeploy.Model.RegisterApplicationRevisionRequest { ApplicationName = appName, Revision = revLocation }; var regResponse = cdClient.RegisterApplicationRevision(regRequest); var x = 0; } } } }