MS Dynamics 365, Logs, AWS and S3

AWS Cloud and Disk Space... what a nightmare

Resultado de imagem para dilbert disk space

The past few months my work has been more around on cloud automation and using Jenkins, AWS than actually MS Dynamics 365 and different challenges have come up in order to reduce the cost and efficiency of CRM on cloud solution using AWS or Azure. One challenge is, in fact, to send the logs into S3 instead of having them on a local disk, so this way we can reduce the disk space and save some money.

Here are the steps:


//Using`s:
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.S3.Transfer;
//Rest of the code:
//SEND FILES TO S3 Main
public static void Main()
        {
try
            {
                string Filename = internalpath; //Pah of you List of Files ex.d://Program..
                S3FileUpload(Filename);
                Console.WriteLine("File: " + Filename + " - Finished");
                Console.WriteLine("-------------------------------------------------------");
            }
            catch (Exception ex)
            {
               Console.WriteLine("{0} Exception caught.", ex);
            }
         }
        //S3 File Transfer Method
        static void S3FileUpload(string filename)
        {
            string existingBucketName = "*** bucket name ***";
            string filePath = filename;
            TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1));
            // Upload a file, file name is used as the object key name.
            fileTransferUtility.Upload(filePath, existingBucketName);
        }


NOTE: If you run this inside the EC2 instance you will not need to put the Access Key ID and the Secret Access Key but in case you need here follows for the authentication:


        private const string bucketName = "*** bucket name ***";
        private const string keyName = "*** object key ***";
        // Specify your bucket region (an example region is shown).
        private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
        private static IAmazonS3 client;



Comments

  1. Nice blog! Really this was very useful blog for us. Nice sharing about
    PL-400T00-AC: Microsoft Power Platform Developer

    ReplyDelete
  2. Thanks for sharing this informative article on HUGO ROCHA SILVA - POWER PLATFORM & DYNAMICS CRM FROM AZURE TO Z. With important practical screenshot. If you have any requirement to Hire MS Dynamics CRM consultant to accelerate your company's success by evaluating new solutions and customizing existing ones with Microsoft Dynamics. Please contact us.

    ReplyDelete

Post a Comment