DEV Community: Binat The latest articles on DEV Community by Binat (@binat). https://dev.to/binat https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1210744%2F2196d794-c3bf-477a-8033-67e430e64b71.jpg DEV Community: Binat https://dev.to/binat en Using Bash to upload files to AWS S3 Binat Fri, 13 Dec 2024 01:01:30 +0000 https://dev.to/binat/bash-script-for-uploading-files-to-aws-s3-44en https://dev.to/binat/bash-script-for-uploading-files-to-aws-s3-44en <p>This blog post describes how to create a Bash script which can be used from the command line to upload files on to AWS S3. In order to follow along, you will need:</p> <ul> <li>An AWS Account </li> <li>The AWS CLI Downloaded and installed on your machine</li> <li>The AWS CLI configured with your credentials</li> <li>Git installed on your machine</li> </ul> <p>For guidance on how to download and configure AWS CLI for Windows, see my post <a href="proxy.php?url=https://dev.to/binat/install-and-configure-aws-cli-on-windows-1obh">here</a>.</p> <h3> Use cases </h3> <p>We will satisfy the following use cases in this script:</p> <ul> <li>Parse command line arguments $1, $2, to take in the file and bucket names. </li> <li>Validate the input.</li> <li>Provide error messages for incorrect or missing inputs.</li> <li>Before uploading check if the file exists locally, if not provide feedback. </li> <li>Before uploading, check if the bucket exists, if not create it, provide feedback.</li> <li>Before uploading, check if the file exists in the bucket</li> <li>If there is an error, capture it and display it to the user.</li> </ul> <h3> Create a bash file </h3> <ul> <li>Open a git bash prompt and navigate to the folder you will be working in. </li> <li>Create a bash script using the touch command. </li> </ul> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">touch </span>upload_to_s3.sh </code></pre> </div> <ul> <li>Use the chmod command inside a git bash terminal to give the script executable permissions. </li> </ul> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">chmod</span>+x upload_to_s3.sh </code></pre> </div> <ul> <li>Open up the script in an editor. I am using Visual Studio Code.</li> <li>All bash scripts start with a shebang. Add one to the top of the script. </li> </ul> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="c">#!/bin/bash</span> </code></pre> </div> <h3> Parse command line arguments </h3> <p>In bash arguments are represented by $1 and $2. Let's set two variables, the name of the file we wish to upload, and the name of the S3 bucket we want to upload to, to $1 and $2 respectively.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="o">!</span><span class="c">#/bin/bash</span> <span class="nv">FILENAME</span><span class="o">=</span><span class="nv">$1</span> <span class="nv">S3BUcKETNAME</span><span class="o">=</span><span class="nv">$2</span> <span class="nb">echo</span> <span class="nv">$FILENAME</span> <span class="nb">echo</span> <span class="nv">$S3BUCKETNAME</span> </code></pre> </div> <p>Run the script with the following command, remember to pass in arguments, <code>./upload_to_s3.sh arg1 arg2</code></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gpxwzsp7eaa7gvu8lil.PNG" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gpxwzsp7eaa7gvu8lil.PNG" alt="Image description" width="800" height="67"></a></p> <p>Create a test file to upload. <code>touch testfile.txt</code></p> <h3> Check if inputs are valid </h3> <p>Add an if statement to check if the two inputs are valid.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="k">if</span> <span class="o">[[</span> <span class="nt">-z</span> <span class="nv">$FILENAME</span> <span class="o">]]</span> <span class="k">then</span>     <span class="nb">echo </span>Please provide a filename. <span class="k">fi if</span> <span class="o">[[</span> <span class="nt">-z</span> <span class="nv">$S3BUCKETNAME</span> <span class="o">]]</span> <span class="k">then</span>     <span class="nb">echo </span>Please provide a bucketname. <span class="k">fi</span> </code></pre> </div> <p>Run the script without inputs to check the conditions work. You should get these responses:</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd318hncaxq4hwzdwtq7f.PNG" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd318hncaxq4hwzdwtq7f.PNG" alt="Image description" width="800" height="85"></a></p> <p>It's a good idea to test the script with correct and incorrect inputs at each stage. This will ensure you catch any errors.</p> <p>If a filename is provided, we want to check if the file exists. If it does not, return the error message.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="k">if</span> <span class="o">[[</span> <span class="o">!</span> <span class="nt">-f</span> <span class="nv">$FILENAME</span> <span class="o">]]</span> <span class="k">then</span>     <span class="nb">echo </span>File not found! <span class="k">fi</span> </code></pre> </div> <h3> Check if the bucket exists, if not, create it. </h3> <p>Next we will check if the bucket already exists or not, and provide feedback depending on the result.</p> <ul> <li>If the bucket does not exist and the name of the bucket is the appropriate length: create the bucket.</li> <li>If the bucket exists but we do not own it: return an error message.</li> <li>If the bucket does not exist but the proposed name is not within the required parameters: return an error message.</li> <li>If the bucket already exists and we do own it: return a message. </li> </ul> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="c"># check if the bucket exists</span> <span class="nv">bucketstatus</span><span class="o">=</span><span class="si">$(</span>aws s3api head-bucket <span class="nt">--bucket</span> <span class="s2">"</span><span class="k">${</span><span class="nv">S3BUCKETNAME</span><span class="k">}</span><span class="s2">"</span> 2&gt;&amp;1 <span class="si">)</span> <span class="c"># search the bucketstatus result for the Not Found result, if the bucket is</span> <span class="c"># indeed not found, echo that as a response, then create the bucket</span> <span class="k">if </span><span class="nb">echo</span> <span class="nv">$bucketstatus</span> | <span class="nb">grep</span> <span class="nt">-q</span> <span class="s2">"Not Found"</span><span class="p">;</span> <span class="k">then</span>     <span class="nb">echo </span>Bucket not found.     <span class="c"># this command creates the bucket</span>     aws s3 mb s3://<span class="nv">$S3BUCKETNAME</span> <span class="k">elif </span><span class="nb">echo</span> <span class="nv">$bucketstatus</span> | <span class="nb">grep</span> <span class="nt">-q</span> <span class="s2">"Forbidden"</span><span class="p">;</span> <span class="k">then</span>     <span class="nb">echo </span>Bucket exists but not owned. <span class="k">elif </span><span class="nb">echo</span> <span class="nv">$bucketstatus</span> | <span class="nb">grep</span> <span class="s2">"Bad Request"</span><span class="p">;</span> <span class="k">then</span>     <span class="nb">echo </span>Bucket name is less than 3 or greater than 63 characters. <span class="k">else</span>     <span class="nb">echo </span>Bucket already exists. <span class="k">fi</span> </code></pre> </div> <h3> Create a function to upload the file </h3> <p>Making this a function will allow us to reuse this piece of code without repeating it. This will also check if the file upload was successful, and return and error message if it fails.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>UPLOAD<span class="o">()</span> <span class="o">{</span> <span class="nb">echo </span>Uploading file. aws s3 <span class="nb">cp</span> <span class="nv">$FILENAME</span> s3://<span class="nv">$S3BUCKETNAME</span> <span class="c"># this checks if the previous command is equal to 0 or not, in bash a 0 return indicates a successful completion of command, while a non-zero return indicates an error occured.</span> <span class="k">if</span> <span class="o">[[</span> <span class="nv">$?</span> <span class="nt">-eq</span> 0 <span class="o">]]</span> <span class="k">then </span><span class="nb">echo </span>File uploaded successfully <span class="nb">exit </span>0 <span class="k">else </span><span class="nb">echo </span>An error occured. <span class="nb">exit </span>1 <span class="k">fi</span> <span class="o">}</span> </code></pre> </div> <h3> Check if the file already exists inside the bucket </h3> <p>Check if the file already exists inside the bucket. If it does, offer an option to replace the existing file, respond appropriately based on the user's input.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="c"># this checks if the file exists inside the bucket</span> <span class="nv">FILE_EXISTS</span><span class="o">=</span><span class="si">$(</span>aws s3api head-object <span class="nt">--bucket</span> <span class="nv">$S3BUCKETNAME</span> <span class="nt">--key</span> <span class="nv">$FILENAME</span><span class="si">)</span> <span class="c"># if the file does exist</span> <span class="k">if</span> <span class="o">[[</span> <span class="o">!</span><span class="nv">$FILE_EXISTS</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then </span><span class="nb">echo </span>File already exists <span class="nb">echo </span>Do you want replace the file <span class="k">in </span>the bucket with this version? Y/N? <span class="c"># take in the user's answer and if it is yes, then upload the new version of the file.</span> <span class="nb">read </span>ANSWER <span class="k">if</span> <span class="o">[[</span> <span class="nv">$ANSWER</span> <span class="o">=</span> Y <span class="o">]]</span> <span class="k">then </span>UPLOAD <span class="nv">$FILENAME</span> <span class="nv">$S3BUCKETNAME</span> <span class="k">else </span><span class="nb">exit </span><span class="k">fi</span> <span class="c"># if the file does not already exist in the bucket, then upload the file.</span> <span class="k">else </span><span class="nb">echo </span>Uploading UPLOAD <span class="nv">$FILENAME</span> <span class="nv">$S3BUCKETNAME</span> <span class="k">fi</span> </code></pre> </div> <h3> Test the script </h3> <p>Run the script <code>./bash-uploader-cli.sh filename bucketname</code> to test it. Use the following command to check if the file has been uploaded to the correct bucket.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>aws s3 <span class="nb">ls </span>s3://bucketname </code></pre> </div> <p>You can use this command to delete the bucket and files inside them after testing.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>aws s3 rb <span class="nt">--force</span> s3://bucketname </code></pre> </div> <p>Run the script again with the same file, or a different bucket name to ensure it responds appropriately.</p> <p>You can find the script at this <a href="proxy.php?url=https://github.com/naturalneuralnet/cloud_uploader" rel="noopener noreferrer">GitHub repository</a>. </p> <p>Thanks for reading this guide, I hope it was helpful.</p> aws bash awscli beginners Install and Configure AWS CLI on Windows Binat Tue, 22 Oct 2024 16:21:32 +0000 https://dev.to/binat/install-and-configure-aws-cli-on-windows-1obh https://dev.to/binat/install-and-configure-aws-cli-on-windows-1obh <p>Welcome to this guide on how to install and configure the AWS command line interface. The command line interface is a powerful tool for programmatically managing and configuring AWS services and automating processes for those resources using scripts.</p> <h3> Download and run the installer </h3> <p>Download the installer <a href="proxy.php?url=https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" rel="noopener noreferrer">here</a></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fehe9xkdf4zj498yb7zid.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fehe9xkdf4zj498yb7zid.png" alt="Image description|400" width="800" height="510"></a></p> <p>Follow the Installation Wizard to complete the installation.</p> <h3> Verify Installation </h3> <p>Open up a command prompt and run <code>aws --version</code></p> <p>You should see the version number in response.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftifnsb9oq03zda7muajz.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftifnsb9oq03zda7muajz.png" alt="Image description | 400" width="800" height="94"></a></p> <h3> Configure Access </h3> <p>Firstly, we need to create a user with permissions for the AWS resources we want to access programmatically. In AWS permissions are explicitly set for users with the IAM (Identity Access Management) console.</p> <p>-&gt; Log into AWS console. Find the IAM dashboard by typing IAM into the search bar.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12xgejr86jr6mo1ph51i.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12xgejr86jr6mo1ph51i.png" alt="Image description" width="800" height="179"></a></p> <p>-&gt; On the left hand panel, click users, and then click create user.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqz22z3re93g9fnv6y6v.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqz22z3re93g9fnv6y6v.png" alt="Image description" width="800" height="143"></a></p> <p>-&gt; Give the user a name, and click next. Do not tick the console access button, we only want this user to have programmatic access.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq7jfuvv9xizmqx41vqa.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq7jfuvv9xizmqx41vqa.png" alt="Image description" width="800" height="330"></a></p> <p>-&gt; For permissions, attach an existing policy, search for and add AmazonS3FullAccess.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsuh83hxi0whsywv0iq6.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsuh83hxi0whsywv0iq6.png" alt="Image description" width="800" height="408"></a></p> <p>-&gt; Review and create user.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ik2gi8vdqv3yvs9mlf2.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ik2gi8vdqv3yvs9mlf2.png" alt="Image description" width="800" height="486"></a></p> <h4> Create Access Key </h4> <p>-&gt; From the users dashboard select the user we just created. Then click on create access key.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmyqlu3kgrwq77cycw9zs.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmyqlu3kgrwq77cycw9zs.png" alt="Image description" width="800" height="192"></a></p> <p>-&gt; Select other and click next.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2x52wj9qt26yoljmgrh.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2x52wj9qt26yoljmgrh.png" alt="Image description" width="678" height="549"></a></p> <p>-&gt; Tags are optional so leave as is and click create access key.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmkqojzugw2syhyzl472d.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmkqojzugw2syhyzl472d.png" alt="Image description" width="780" height="242"></a></p> <p>-&gt; You should be on the retrieve access key page. Stay on this page for the next step. Please note the security warnings regarding access keys.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqsycamxe4jlheyajbfy.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqsycamxe4jlheyajbfy.png" alt="Image description" width="800" height="494"></a></p> <h3> CLI configuration </h3> <p>Inside your command prompt run <code>aws configure</code></p> <p>As the command requests, copy and paste in your access key and secret access key. Type in your region, which is available in the top right corner of the AWS console. </p> <p>It should look something like this</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9zootlhohilha6zirls.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9zootlhohilha6zirls.png" alt="Image description" width="800" height="117"></a></p> <p>Click done on the retrieve access key page.</p> <h3> Test configuration </h3> <p>To ensure your permissions are working correctly, create an s3 bucket from the CLI with the following command. AWS S3 bucket names must be unique.</p> <p><code>aws s3 mb s3://nat-blog-test-1</code></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihlnnxmsb2wqw5drnsdq.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihlnnxmsb2wqw5drnsdq.png" alt="Image description" width="564" height="107"></a></p> <p>List the contents of the bucket, it is empty so nothing is listed.</p> <p><code>aws s3 ls s3://nat-blog-test-1</code></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3wtma5gp9yvqo3rpien.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3wtma5gp9yvqo3rpien.png" alt="Image description" width="589" height="76"></a></p> <p>Create a file to upload to the s3 bucket.</p> <p><code>echo hello aws &gt; testfile.txt</code></p> <p>Use the cp (copy) command to upload it to the bucket.</p> <p><code>aws s3 cp &lt;path to file&gt; s3://bucket-name</code></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbugopiu6lv9j98ugjo5p.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbugopiu6lv9j98ugjo5p.png" alt="Image description" width="800" height="58"></a></p> <p>You can either list the contents of the bucket again or go to S3 on the AWS console and confirm the bucket has been created and the file has been uploaded. If the file is there, then the configuration has been successful.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9t62x8pi2q3pxnhwicw0.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9t62x8pi2q3pxnhwicw0.png" alt="Image description" width="800" height="207"></a></p> <p>Thanks for reading :)</p> aws microsoft cloud beginners Installing Docker On Windows Binat Wed, 12 Jun 2024 17:16:06 +0000 https://dev.to/binat/installing-docker-on-windows-ma4 https://dev.to/binat/installing-docker-on-windows-ma4 <p>It was a little finicky for me to use Docker from the Windows Command Line. </p> <p>This tutorial will ensure you have no such problems.</p> <p>There are three main steps:</p> <ol> <li>Install the Windows Subystem (WSL) 2 Linux distribution</li> <li>Download and Install Docker Desktop for Windows</li> <li>Configure Docker Desktop to access Docker from WSL</li> </ol> <h4> Installing WSL 2 </h4> <p>Note: For a general tutorial see the WSL documentation <a href="proxy.php?url=https://learn.microsoft.com/en-us/windows/wsl/install" rel="noopener noreferrer">here</a></p> <p>Open the command prompt in administrator mode by right clicking and selecting run as administrator.</p> <p>Run the following command <code>wsl --install</code></p> <p>Check which version is installed with <code>wsl -l -v</code></p> <p>If it is not already version 2, set WSL to the correct distribution with <code>wsl --set-default-version 2</code> </p> <h4> Download and Install Docker Desktop </h4> <p>Download and install Docker Desktop for Windows from <a href="proxy.php?url=https://docs.docker.com/desktop/install/windows-install/" rel="noopener noreferrer">here</a></p> <p>Once installation is finished, you should be able to open the Docker Desktop application.</p> <h4> Configure Docker Desktop </h4> <p>In Docker Desktop, go to Settings, then select the resources tab. Set the terminal to be integrated with the WSL distribution. </p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrxff7p8ycgoy0d0jybr.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrxff7p8ycgoy0d0jybr.png" alt="Image description" width="800" height="354"></a></p> <p>Docker should now work from the command line.</p> <p>Thank you for reading my first post!</p> docker linux microsoft devops