<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: William Wayn</title>
    <description>The latest articles on DEV Community by William Wayn (@willzwayn).</description>
    <link>https://dev.to/willzwayn</link>
    <image>
      <url>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%2F445509%2Fb4bd6169-66ff-458d-8811-9d60ebbcabf2.jpeg</url>
      <title>DEV Community: William Wayn</title>
      <link>https://dev.to/willzwayn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/willzwayn"/>
    <language>en</language>
    <item>
      <title>AWS EC2 to S3 Access Issues: 'Unable to Locate Credentials' Error</title>
      <dc:creator>William Wayn</dc:creator>
      <pubDate>Sun, 31 Mar 2024 21:30:25 +0000</pubDate>
      <link>https://dev.to/willzwayn/aws-ec2-to-s3-access-issues-unable-to-locate-credentials-error-1hik</link>
      <guid>https://dev.to/willzwayn/aws-ec2-to-s3-access-issues-unable-to-locate-credentials-error-1hik</guid>
      <description>&lt;p&gt;I’m writing this post because I recently came across a perplexing issue while setting up a new EC2 instance, and what’s even more frustrating is that the solution turned out to be quite simple. I only managed to resolve it on my own after many unsuccessful searches on the Internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Everything seemed fine with VPNs and access, but my EC2 instance just couldn’t seem to talk to any AWS resources. To make things even more fun, when I installed the AWS CLI, I got hit with the “&lt;strong&gt;unable to locate credentials. you can configure credentials by running aws configure&lt;/strong&gt;” error.&lt;/p&gt;

&lt;p&gt;After some quality time troubleshooting and closely inspecting what was going on, I had a facepalm moment — it turned out &lt;strong&gt;I had forgotten to set up the IAM role&lt;/strong&gt; when creating the EC2 instance.&lt;/p&gt;

&lt;p&gt;Here’s the straightforward fix for when you find yourself in the same pickle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Creating the EC2 Instance&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Start creating your EC2 instance as usual. When you get to the “&lt;strong&gt;Advanced details&lt;/strong&gt;” part, keep an eye out for the “&lt;strong&gt;IAM instance profile&lt;/strong&gt;” option.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;IAM Instance Profile Setup&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click on “IAM instance profile” and give it the permissions it needs. In my case, I needed to adjust this configuration in &lt;strong&gt;the IAM to match my specific requirements&lt;/strong&gt;. You can use the following IAM policy as a guide, &lt;strong&gt;but don’t forget to tweak it according to your own needs&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;  
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;  
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:Get*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:List*"&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::trusted-data-credits-ACCOUNT-ID"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::trusted-data-clients-ACCOUNT-ID"&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;  
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;  
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:Get*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:List*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObject*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:DeleteObject"&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::analytics-data-credits-ACCOUNT-ID"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::analytics-data-clients-ACCOUNT-ID"&lt;/span&gt;&lt;span class="w"&gt;  
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;  
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;  
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;  
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Instance Launch&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Carry on with the EC2 instance creation process like you normally would. When your shiny new instance starts up, it’ll have the right IAM role attached, granting it the permissions it needs to play nicely with AWS resources.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;In a nutshell, in the wild world of AWS, sometimes it’s the little things that trip you up. But by remembering to configure that IAM instance profile when you’re setting up your EC2 instance, you can save yourself from some serious troubleshooting headaches and ensure your AWS resources are just a connection away.&lt;/p&gt;

&lt;p&gt;Happy cloud adventures!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
    </item>
  </channel>
</rss>
