title: Python app on EC2 deployed by terraform cannot access secrets
body: <p>I have a fargate instance which uses AWS secrets to fetch database credentials but it cannot read the credentials.</p>
  <p>Fetching secrets works in Lambda as well as running it locally if I provide a key locally. I can print and log the values and the code executes in the last two cases. The library used to fetch th secrets are the same in the fargate docker image, the lambda and local tests(apart from needing to provide an access key locally)</p>
  <p>I am using Terraform to create my EC2, and I gave my ec2 these riles.</p>
  <pre><code>&quot;Action&quot;: [
      &quot;secretsmanager:GetResourcePolicy&quot;,
      &quot;secretsmanager:GetSecretValue&quot;,
      &quot;secretsmanager:DescribeSecret&quot;,
      &quot;secretsmanager:ListSecretVersionIds&quot;
    ],
    &quot;Effect&quot;: &quot;Allow&quot;,
    &quot;Resource&quot;: [
          &quot;arn:aws:secretsmanager:eu-west-2:xxxxxxx:secret:xxx-xxx-xxx&quot;
      ]
  </code></pre>
  <p>The error I am getting is simply</p>
  <pre><code>Unable to locate credentials
  </code></pre>
  <p>This is my first fargate app. My health-check works and the code executes until this point.</p>
  <p>My code looks like this</p>
  <pre><code>    endpoint_url = &quot;https://xxxxxx.eu-west-2.amazonaws.com&quot;
      secret_name = secret
      region_name = &quot;eu-west-2&quot;
  
      logger.info(&quot;Pre secrets&quot;)
      try:
          session = boto3.session.Session()
      except Exception as e:
          logger.info(e)
  
      client = session.client(
          service_name=&quot;secretsmanager&quot;,
          region_name=region_name,
          endpoint_url=endpoint_url,
      )
  </code></pre>
  <p>Is there anything I could have overlooked that I need to look at?</p>
  <p>Thank you,</p>