CreateApplication() public method

Creates an application.
/// An application with the specified name already exists with the applicable IAM user /// or AWS account. /// /// More applications were attempted to be created than are allowed. /// /// The minimum number of required application names was not specified. /// /// The application name was specified in an invalid format. ///
public CreateApplication ( CreateApplicationRequest request ) : Amazon.CodeDeploy.Model.CreateApplicationResponse
request Amazon.CodeDeploy.Model.CreateApplicationRequest Container for the necessary parameters to execute the CreateApplication service method.
return Amazon.CodeDeploy.Model.CreateApplicationResponse
Example #1
0
        public string Push(AmazonS3Client s3Client, AmazonCodeDeployClient codeDeployClient)
        {
            var zipFileName = string.Format("{0}.{1}.{2}.zip", ApplicationSetName, Version, BundleName);
            var tempPath = Path.Combine(Path.GetTempPath(), zipFileName + "." + Guid.NewGuid() + ".zip");

            ZipFile.CreateFromDirectory(_bundleDirectory.FullName, tempPath, CompressionLevel.Optimal, false, Encoding.ASCII);

            var allTheBuckets = s3Client.ListBuckets(new ListBucketsRequest()).Buckets;

            if (!allTheBuckets.Exists(b => b.BucketName == Bucket))
            {
                s3Client.PutBucket(new PutBucketRequest { BucketName = Bucket, UseClientRegion = true });
            }

            var putResponse = s3Client.PutObject(new PutObjectRequest
            {
                BucketName = Bucket,
                Key = zipFileName,
                FilePath = tempPath,
            });

            var registration = new RegisterApplicationRevisionRequest
            {
                ApplicationName = CodeDeployApplicationName,
                Description = "Revision " + Version,
                Revision = new RevisionLocation
                {
                    RevisionType = RevisionLocationType.S3,
                    S3Location = new S3Location
                    {
                        Bucket = Bucket,
                        BundleType = BundleType.Zip,
                        Key = zipFileName,
                        Version = Version
                    }
                }
            };
            try
            {
                codeDeployClient.RegisterApplicationRevision(registration);
            }
            catch (ApplicationDoesNotExistException)
            {
                codeDeployClient.CreateApplication(new CreateApplicationRequest { ApplicationName = CodeDeployApplicationName });
                codeDeployClient.RegisterApplicationRevision(registration);
            }

            return putResponse.ETag;
        }