static void TestEncryptedS3(EncryptionMaterials encryptionMaterials) { string bucket_Name = null; AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials); bucket_Name = TdwUtils.rootBucketName + "encrypted-content"; try { AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucket_Name); } catch (Exception ex) { ex = null; } bucket_Name = TdwUtils.CreateBucket(s3Client, bucket_Name); string dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPath); byte[] dataBytes = TdwUtils.FileToArray(dataPath); PutObjectRequest request = new PutObjectRequest() { BucketName = bucket_Name, Key = TdwUtils.keyName, InputStream = new MemoryStream(dataBytes) }; PutObjectResponse response = s3Client.PutObject(request); Console.WriteLine("===============>TestEncryptedS3 START<==============="); Console.WriteLine("Encryption method was:"); Console.WriteLine(response.ServerSideEncryptionMethod); Console.WriteLine("===============>TestEncryptedS3 END<==============="); }
static void CopyTemplatesToS3(EncryptionMaterials encryptionMaterials) { string bucket_Name = null; string dataPath = null; byte[] dataBytes = null; PutObjectRequest request = null; PutObjectResponse response = null; //AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials); AmazonS3Client s3Client = new AmazonS3Client(); try { TdwUtils.TearDownS3BucketByPrefix(s3Client, "tdwcftdev"); AmazonS3Util.DeleteS3BucketWithObjects(s3Client, QSS3BucketName); } catch (Exception ex) { ex = null; } bucket_Name = TdwUtils.CreateBucket(s3Client, QSS3BucketName); ///Cross stack communication, Parent dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathParentSubnet); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathParentSubnet.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Cross stack communication, first child dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathChildSubnetProducer); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathChildSubnetProducer.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Cross stack communication, second child dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathChildSubnet); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathChildSubnet.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Application Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathApplication); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathApplication.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); //Config Rules dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathConfigRules); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathConfigRules.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Iam Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathIam); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathIam.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); //Kinesis dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathKinesis); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathKinesis.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Logging Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathLogging); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathLogging.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Main Bastion Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathBastion); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathBastion.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Management Vpc Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathManagementVpc); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathManagementVpc.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///Prod Vpc Template dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathProductionVpc); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathProductionVpc.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); ///ChangeSet Template for main bastion dataPath = TdwUtils.bingPathToAppDir(TdwUtils.cfClassPathBastionChangeSet); dataBytes = TdwUtils.FileToArray(dataPath); request = new PutObjectRequest() { BucketName = QSS3BucketName, Key = QSS3KeyPrefix + TdwUtils.cfClassPathBastionChangeSet.Replace("tdw_cf_template\\", ""), InputStream = new MemoryStream(dataBytes) }; response = s3Client.PutObject(request); }