<?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: Leandro Salomon</title>
    <description>The latest articles on DEV Community by Leandro Salomon (@leandrosalo).</description>
    <link>https://dev.to/leandrosalo</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%2F657771%2Fdbd70520-3b64-4093-8710-7abda5b1015d.jpeg</url>
      <title>DEV Community: Leandro Salomon</title>
      <link>https://dev.to/leandrosalo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leandrosalo"/>
    <language>en</language>
    <item>
      <title>[NodeJs/AWS] Self-reload SSO keys in credentials file</title>
      <dc:creator>Leandro Salomon</dc:creator>
      <pubDate>Mon, 28 Jun 2021 14:07:02 +0000</pubDate>
      <link>https://dev.to/leandrosalo/nodejs-aws-auto-reload-sso-keys-in-credentials-file-10</link>
      <guid>https://dev.to/leandrosalo/nodejs-aws-auto-reload-sso-keys-in-credentials-file-10</guid>
      <description>&lt;h1&gt;
  
  
  AWS SSO Credentials Script
&lt;/h1&gt;

&lt;p&gt;Hello everyone! I just wanted to share a script i made in Nodejs using the V3 AWS Sdk for javascript.&lt;br&gt;
This is a script to (almost)automatically update your local credentials file.&lt;br&gt;
I say &lt;em&gt;almost&lt;/em&gt; because at some point you'll need to click a button (or two in the worst scenario).&lt;/p&gt;
&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;The SSO credentials expires every day, so I did not want to update this file manually. This script is very useful when you have a lot of accounts/roles in your organization.&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Node.js - &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Install Node.js&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;

&lt;p&gt;First of all download the code from github - &lt;a href="https://github.com/leandrosalo/aws-sso-creds-tool" rel="noopener noreferrer"&gt;aws-sso-creds-tool&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/leandrosalo/aws-sso-creds-tool.git&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Update .env file with the correct params
&lt;/h3&gt;

&lt;p&gt;It is required to set the sso url like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;SSO_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://&amp;lt;your-project&amp;gt;.awsapps.com/start#/"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The credentials will be stored as &lt;strong&gt;[account-name_AWSRoleName]&lt;/strong&gt;.&lt;br&gt;
If you want to store it as &lt;strong&gt;[123456789098_AWSRoleName]&lt;/strong&gt; add this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;USE_ACCOUNT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;if you want a different profile name pattern update the code...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It uses &lt;em&gt;us-east-1&lt;/em&gt; as default aws region and searches for the credentials file in the default path.&lt;br&gt;
If you want to change it, add this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1
&lt;span class="nv"&gt;AWS_CREDENTIALS_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/Users/you/.aws/credentials
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  First time use
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;npm install&lt;/code&gt; in this folder&lt;/li&gt;
&lt;li&gt;Update the &lt;code&gt;.env&lt;/code&gt; with the correct values&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;node app.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;At some point the aws webpage will popup

&lt;ol&gt;
&lt;li&gt;Log in to aws if you are not already&lt;/li&gt;
&lt;li&gt;The code for device authentication will be auto filled&lt;/li&gt;
&lt;li&gt;Click on Sign In&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F7031690%2F123454656-2e73bb00-d5b7-11eb-8db7-a79fda950bc5.png" class="article-body-image-wrapper"&gt;&lt;img alt="Screen Shot 2021-06-25 at 11 59 23" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F7031690%2F123454656-2e73bb00-d5b7-11eb-8db7-a79fda950bc5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the success alert shows then come back to the terminal and press a key&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F7031690%2F123454778-52cf9780-d5b7-11eb-9081-c2a08c2430b0.png" class="article-body-image-wrapper"&gt;&lt;img alt="Screen Shot 2021-06-25 at 11 59 36" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F7031690%2F123454778-52cf9780-d5b7-11eb-9081-c2a08c2430b0.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Done!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For consequents runs just start from step 3.&lt;/p&gt;

&lt;h1&gt;
  
  
  Feel free to share, copy and improve!
&lt;/h1&gt;

</description>
      <category>aws</category>
      <category>credentias</category>
      <category>sso</category>
      <category>awscredentials</category>
    </item>
  </channel>
</rss>
