-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-profile.html
441 lines (324 loc) · 28.8 KB
/
aws-profile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.0.0-rc1">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
<script class="next-config" data-name="main" type="application/json">{"hostname":"www.hwchiu.com","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.17.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}}</script><script src="/js/config.js"></script>
<meta name="description" content="本文分享如何透過一些常見的方法或是別人撰寫好的工具來提供一個方便的管理工具,讓操作者可以更方便的再多個 AWS 帳號中進行切換">
<meta property="og:type" content="article">
<meta property="og:title" content="Management AWS Profiles">
<meta property="og:url" content="https://www.hwchiu.com/aws-profile.html">
<meta property="og:site_name" content="Hwchiu Learning Note">
<meta property="og:description" content="本文分享如何透過一些常見的方法或是別人撰寫好的工具來提供一個方便的管理工具,讓操作者可以更方便的再多個 AWS 帳號中進行切換">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2019-06-07T18:49:03.000Z">
<meta property="article:modified_time" content="2023-06-23T05:16:12.599Z">
<meta property="article:author" content="Hwchiu">
<meta property="article:tag" content="AWS">
<meta property="article:tag" content="Shell">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://www.hwchiu.com/aws-profile.html">
<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"en","comments":true,"permalink":"https://www.hwchiu.com/aws-profile.html","path":"aws-profile.html","title":"Management AWS Profiles"}</script>
<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Management AWS Profiles | Hwchiu Learning Note</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-54006186-1"></script>
<script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-54006186-1","only_pageview":false}</script>
<script src="/js/third-party/analytics/google-analytics.js"></script>
<noscript>
<link rel="stylesheet" href="/css/noscript.css">
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
<div class="headband"></div>
<main class="main">
<div class="column">
<header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="Toggle navigation bar" role="button">
<span class="toggle-line"></span>
<span class="toggle-line"></span>
<span class="toggle-line"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<i class="logo-line"></i>
<p class="site-title">Hwchiu Learning Note</p>
<i class="logo-line"></i>
</a>
<p class="site-subtitle" itemprop="description">kubernetes, sdn, linux,devops</p>
<img class="custom-logo-image" src="/uploads/hwchiu.jpg" alt="Hwchiu Learning Note">
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger" aria-label="Search" role="button">
</div>
</div>
</div>
<nav class="site-nav">
<ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>Sitemap</a></li>
</ul>
</nav>
</header>
<aside class="sidebar">
<div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
<ul class="sidebar-nav">
<li class="sidebar-nav-toc">
Table of Contents
</li>
<li class="sidebar-nav-overview">
Overview
</li>
</ul>
<div class="sidebar-panel-container">
<!--noindex-->
<div class="post-toc-wrap sidebar-panel">
<div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Preface"><span class="nav-number">1.</span> <span class="nav-text">Preface</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Introduction"><span class="nav-number">2.</span> <span class="nav-text">Introduction</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Usage"><span class="nav-number">3.</span> <span class="nav-text">Usage</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Solution"><span class="nav-number">4.</span> <span class="nav-text">Solution</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#oh-my-zsh-aws"><span class="nav-number">5.</span> <span class="nav-text">oh-my-zsh aws</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Usage-1"><span class="nav-number">5.1.</span> <span class="nav-text">Usage</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Configuration"><span class="nav-number">5.2.</span> <span class="nav-text">Configuration</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%80%8B%E4%BA%BA%E8%B3%87%E8%A8%8A"><span class="nav-number">6.</span> <span class="nav-text">個人資訊</span></a></li></ol></div>
</div>
<!--/noindex-->
<div class="site-overview-wrap sidebar-panel">
<div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
<img class="site-author-image" itemprop="image" alt="Hwchiu"
src="/uploads/avatar.jpg">
<p class="site-author-name" itemprop="name">Hwchiu</p>
<div class="site-description" itemprop="description">kubernetes/SDN/DevOps</div>
</div>
<div class="site-state-wrap animated">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">352</span>
<span class="site-state-item-name">posts</span>
</a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">115</span>
<span class="site-state-item-name">tags</span></a>
</div>
</nav>
</div>
<div class="links-of-author animated">
<span class="links-of-author-item">
<a href="https://github.com/hwchiu" title="GitHub → https://github.com/hwchiu" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
</span>
<span class="links-of-author-item">
<a href="mailto:sppsorrg@gmail.com" title="E-Mail → mailto:sppsorrg@gmail.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
</span>
<span class="links-of-author-item">
<a href="https://twitter.com/hw_chiu" title="Twitter → https://twitter.com/hw_chiu" rel="noopener me" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
</span>
<span class="links-of-author-item">
<a href="https://www.facebook.com/technologynoteniu" title="FB Page → https://www.facebook.com/technologynoteniu" rel="noopener me" target="_blank"><i class="fab fa-facebook fa-fw"></i>FB Page</a>
</span>
<span class="links-of-author-item">
<a href="https://www.youtube.com/channel/UCoYY8K9fbfDtTY7m68UCATA/videos" title="YouTube → https://www.youtube.com/channel/UCoYY8K9fbfDtTY7m68UCATA/videos" rel="noopener me" target="_blank"><i class="fab fa-youtube fa-fw"></i>YouTube</a>
</span>
<span class="links-of-author-item">
<a href="https://instagram.com/hwchiu" title="Instagram → https://instagram.com/hwchiu" rel="noopener me" target="_blank"><i class="fab fa-instagram fa-fw"></i>Instagram</a>
</span>
</div>
</div>
</div>
</div>
</aside>
</div>
<div class="main-inner post posts-expand">
<div class="post-block">
<article itemscope itemtype="http://schema.org/Article" class="post-content" lang="en">
<link itemprop="mainEntityOfPage" href="https://www.hwchiu.com/aws-profile.html">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/uploads/avatar.jpg">
<meta itemprop="name" content="Hwchiu">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Hwchiu Learning Note">
<meta itemprop="description" content="kubernetes/SDN/DevOps">
</span>
<span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
<meta itemprop="name" content="Management AWS Profiles | Hwchiu Learning Note">
<meta itemprop="description" content="本文分享如何透過一些常見的方法或是別人撰寫好的工具來提供一個方便的管理工具,讓操作者可以更方便的再多個 AWS 帳號中進行切換">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
Management AWS Profiles
</h1>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2019-06-08 02:49:03" itemprop="dateCreated datePublished" datetime="2019-06-08T02:49:03+08:00">2019-06-08</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2023-06-23 13:16:12" itemprop="dateModified" datetime="2023-06-23T13:16:12+08:00">2023-06-23</time>
</span>
<span class="post-meta-item" title="Views" id="busuanzi_container_page_pv">
<span class="post-meta-item-icon">
<i class="far fa-eye"></i>
</span>
<span class="post-meta-item-text">Views: </span>
<span id="busuanzi_value_page_pv"></span>
</span>
</div>
<div class="post-description">本文分享如何透過一些常見的方法或是別人撰寫好的工具來提供一個方便的管理工具,讓操作者可以更方便的再多個 AWS 帳號中進行切換</div>
</div>
</header>
<div class="post-body" itemprop="articleBody"><h1 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h1><p>如果有想要透過 Command Line Interface 來管理 AWS 帳號的人,應該都會有參考這篇官方的<a target="_blank" rel="noopener" href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">Configuring the AWS CLI</a> 來設定相關的工具與環境。</p>
<p>這邊簡單做個快速的概括,想要在 Shell 上面操作 AWS 帳戶的話,要執行下列的動作</p>
<ol>
<li>下載並且安裝 awscli (可以透過 pip 安裝)</li>
<li>設定 AWS Profile</li>
</ol>
<p>對於一般使用 <code>AWS</code> 通常到這一個步驟就差不多完成了,能夠將帳戶給設定完成並且使用 <code>aws</code> 相關的指令來存取公有雲上的資源。</p>
<p>然而對於部分企業或是使用者來說,基於商業/安全/其他考量,可能會有多組 <code>AWS</code> 的帳號,要如何在 Shell 中方便且快速地切換不同的 <code>AWS</code> 帳號則是一個有趣的問題。<br>接下來會跟大家分享我自己是如何管理多組 <code>AWS</code> 帳號的</p>
<h1 id="Introduction"><a href="#Introduction" class="headerlink" title="Introduction"></a>Introduction</h1><p>再開始探討如何切換多組 <code>AWS</code> 帳號前,我們要先瞭解 <code>aws cli</code> 本身是怎麼運作的。</p>
<p><code>aws cli</code> 本身有兩個檔案用來處理帳號的基本設定以及相關的認證資訊, 分別是<br><code>$HOME/.aws/config</code> 以及 <code>$HOME/.aws/credential</code></p>
<p>其中 <code>$HOME/.aws/config</code> 裡面的格式大概是</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[default]</span><br><span class="line">region = us-west-1</span><br><span class="line">output = json</span><br><span class="line"></span><br><span class="line">[profile Account1]</span><br><span class="line">region = us-west-1</span><br><span class="line">output = json</span><br><span class="line"></span><br><span class="line">[profile Account2]</span><br><span class="line">region = us-west-1</span><br><span class="line">output = json</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[default]</span><br><span class="line">aws_access_key_id = xxxxxxxxxxxxxxxx</span><br><span class="line">aws_secret_access_key = xxxxxxxxxxxxxxxxxxxx</span><br><span class="line"></span><br><span class="line">[Account1]</span><br><span class="line">aws_access_key_id = xxxxxxxxxxxxxxxx</span><br><span class="line">aws_secret_access_key = xxxxxxxxxxxxxxxxxxxx</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[Account2]</span><br><span class="line">aws_access_key_id = xxxxxxxxxxxxxxxx</span><br><span class="line">aws_secret_access_key = xxxxxxxxxxxxxxxxxxxx</span><br></pre></td></tr></table></figure>
<p>當執行 <code>aws</code> 指令時,若沒有特別指定 <code>PROFILE</code> 的名稱,則會使用 <code>default</code><br> 這一組的資訊來存取,否則就會根據其名稱來尋找特定的數值</p>
<h1 id="Usage"><a href="#Usage" class="headerlink" title="Usage"></a>Usage</h1><p>有了上述的概念後,接下來來看一下要如何設定 <code>aws cli</code>。</p>
<ol>
<li>執行時帶入參數 <code>--profile</code> 來指定要使用的 <code>PROFILE</code></li>
<li>透過環境變數 <code>AWS_PROFILE</code> 來指定要使用的 <code>PROFILE</code></li>
</ol>
<h1 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h1><p>以(1)為範例的話,我們可以透過所有的指令都要補上 <code>--profile</code> 來使用,但是這種方式使用上會變成你所有指令都要確保有加上該參數,實務上我個人是沒有很喜歡,覺得管理上比較麻煩。<br>譬如</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">aws iam list-roles --profile Account1</span><br><span class="line">aws iam list-roles --profile Account2</span><br><span class="line">aws iam list-roles --profile Account3</span><br></pre></td></tr></table></figure>
<p>如果今天有一些客製化的腳本,變成腳本中所有的指令都要注意有使用到這個參數,對於一個多人維護的腳本來說,我覺得被忽略的可能性非常高</p>
<p>以(2)為範例的話,就是每次使用前要確保當前的環境變數是什麼,這種情況下每個指令的使用就可以盡量簡單,讓呼叫者自己去確保該指令的面對對象</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> AWS_PROFILE=account1</span><br><span class="line">aws iam list-roles</span><br><span class="line">AWS_PROFILE=account2 aws iam list-roles</span><br></pre></td></tr></table></figure>
<p>套入環境變數的方法滿多種的,上述的方式都可以將該環境變數傳遞到 <code>aws</code> 的指令列中</p>
<p>但是使用這個方法的困難處就在於預設的情況下,你有時候會不知道自己到底當前是什麼樣的 <code>Profile</code>, 這時候就可以搭配 <code>shell prompt</code> 去客製化顯示當前的 <code>AWS_PROFILE</code> 是什麼。</p>
<p>為了解決這個問題,其實可以修改自己習慣使用的 <code>shell</code> 設定檔,搭配一些自行撰寫的 <code>shell function</code> 來動態調整當前的 <code>AWS_PROFILE</code> 環境變數,並且將當前的數值顯示在 <code>shell</code> 的提示命令列上。</p>
<p>就在我完成該功能沒多久後,就發現其實 <code>oh-myzsh</code> 內建的 <code>plugin</code> 有一個幾乎完全一樣的實現功能,這意味其實我根本不需要自己寫,直接啟動該 <code>plugin</code> 即可</p>
<h1 id="oh-my-zsh-aws"><a href="#oh-my-zsh-aws" class="headerlink" title="oh-my-zsh aws"></a>oh-my-zsh aws</h1><h2 id="Usage-1"><a href="#Usage-1" class="headerlink" title="Usage"></a>Usage</h2><p>打開該 aws 套件後,使用上大概會是如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><aws:Account1>╭─hwchiu@hwchius-MBP ~</span><br><span class="line">╰─$</span><br></pre></td></tr></table></figure>
<p>使用指令 <code>asp</code> 搭配 <code>tab</code> 可以列出目前所有設定過的 <code>aws profile</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><aws:LFCORD>╭─hwchiu@hwchius-MBP ~</span><br><span class="line">╰─$ asp</span><br><span class="line">Account1 Account2 Account3 Account4</span><br></pre></td></tr></table></figure>
<p>同時該 <code>aws plugin</code> 也會幫忙設定安裝 <code>aws aws_zsh_completer</code>, 意味你可以透過 <code>tab</code> 的方式來更方便的使用 <code>aws cli</code></p>
<h2 id="Configuration"><a href="#Configuration" class="headerlink" title="Configuration"></a>Configuration</h2><p>基本上參考 <code>on-my-zsh</code> 的設定方式,先到 <code>$HONE/.zshrc</code> 中將 <code>plugin</code> 的選項加入 <code>aws</code> 即可,譬如</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="comment"># Which plugins would you like to load?</span></span><br><span class="line"><span class="comment"># Standard plugins can be found in ~/.oh-my-zsh/plugins/*</span></span><br><span class="line"><span class="comment"># Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/</span></span><br><span class="line"><span class="comment"># Example format: plugins=(rails git textmate ruby lighthouse)</span></span><br><span class="line"><span class="comment"># Add wisely, as too many plugins slow down shell startup.</span></span><br><span class="line">plugins=(git aws)</span><br><span class="line"></span><br><span class="line"><span class="built_in">source</span> <span class="variable">$ZSH</span>/oh-my-zsh.sh</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<p>這邊有一個要注意的是,預設的 <code>aws plugin</code> 使用的是 <code>RPROMPT</code> 而非 <code>PROMPT</code>, 這意味他的顯示會是在畫面最右邊,而非左邊。<br>此外也要注意妳選用的 <code>theme</code> 會不會幫你把 <code>PROMPT</code> 給蓋掉,導致功能失效。<br>譬如我選擇的主題是 <code>bira</code>,所以 <code>PROMPT</code> 以及 <code>RPROMPT</code> 都會被覆蓋掉導致 <code>aws plugin</code> 不會成功。</p>
<p>因此我最後還是自己修改 <code>$HOME/.zsrhc</code> 來處理</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="comment"># alias zshconfig="mate ~/.zshrc"</span></span><br><span class="line"><span class="comment"># alias ohmyzsh="mate ~/.oh-my-zsh"</span></span><br><span class="line">PROMPT=<span class="string">'$(aws_prompt_info)'</span><span class="string">"<span class="variable">$PROMPT</span>"</span></span><br></pre></td></tr></table></figure>
<p>詳細的更多實作可以直接參閱 <a target="_blank" rel="noopener" href="https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/aws">$HOME/.on-my-zsh/plugin/aws</a> 裡面的介紹</p>
<p>藉由這個套件的幫助,我平常就會使用 <code>asp</code> 來切換不同的 <code>AWS Account</code>, 同時透過 <code>shell PROMPT</code> 來知道當前使用的 <code>PROFILE</code>,避免在不同的 <code>Account</code> 執行錯誤的動作</p>
<h1 id="個人資訊"><a href="#個人資訊" class="headerlink" title="個人資訊"></a>個人資訊</h1><p>我目前於 Hiskio 平台上面有開設 Kubernetes 相關課程,歡迎有興趣的人參考並分享,裡面有我從底層到實戰中對於 Kubernetes 的各種想法</p>
<p>線上課程詳細資訊: <a target="_blank" rel="noopener" href="https://course.hwchiu.com/">https://course.hwchiu.com/</a><br>另外,歡迎按讚加入我個人的粉絲專頁,裡面會定期分享各式各樣的文章,有的是翻譯文章,也有部分是原創文章,主要會聚焦於 CNCF 領域<br><a target="_blank" rel="noopener" href="https://www.facebook.com/technologynoteniu">https://www.facebook.com/technologynoteniu</a></p>
<p>如果有使用 Telegram 的也可以訂閱下列頻道來,裡面我會定期推播通知各類文章<br><a target="_blank" rel="noopener" href="https://t.me/technologynote">https://t.me/technologynote</a></p>
<p>你的捐款將給予我文章成長的動力</p>
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="hwchiu" data-color="#000000" data-emoji="" data-font="Cookie" data-text="Buy me a coffee" data-outline-color="#fff" data-font-color="#fff" data-coffee-color="#fd0" ></script>
</div>
<footer class="post-footer">
<div class="followme">
<span>Welcome to my other publishing channels</span>
<div class="social-list">
<div class="social-item">
<a target="_blank" class="social-link" href="https://twitter.com/hw_chiu">
<span class="icon">
<i class="fab fa-twitter"></i>
</span>
<span class="label">Twitter</span>
</a>
</div>
<div class="social-item">
<a target="_blank" class="social-link" href="https://t.me/technologynote">
<span class="icon">
<i class="fab fa-telegram"></i>
</span>
<span class="label">Telegram</span>
</a>
</div>
<div class="social-item">
<a target="_blank" class="social-link" href="/atom.xml">
<span class="icon">
<i class="fa fa-rss"></i>
</span>
<span class="label">RSS</span>
</a>
</div>
</div>
</div>
<div class="post-tags">
<a href="/tags/AWS/" rel="tag"># AWS</a>
<a href="/tags/Shell/" rel="tag"># Shell</a>
</div>
<div class="post-nav">
<div class="post-nav-item">
<a href="/circleci.html" rel="prev" title="CircleCI 使用經驗談">
<i class="fa fa-chevron-left"></i> CircleCI 使用經驗談
</a>
</div>
<div class="post-nav-item">
<a href="/us-life-1.html" rel="next" title="[美國生活] - 菜鳥第一週">
[美國生活] - 菜鳥第一週 <i class="fa fa-chevron-right"></i>
</a>
</div>
</div>
</footer>
</article>
</div>
<div class="comments utterances-container"></div>
</div>
</main>
<footer class="footer">
<div class="footer-inner">
<div class="copyright">
©
<span itemprop="copyrightYear">2023</span>
<span class="with-love">
<i class="fa fa-heart"></i>
</span>
<span class="author" itemprop="copyrightHolder">Hwchiu</span>
</div>
<div class="busuanzi-count">
<span class="post-meta-item" id="busuanzi_container_site_uv">
<span class="post-meta-item-icon">
<i class="fa fa-user"></i>
</span>
<span class="site-uv" title="Total Visitors">
<span id="busuanzi_value_site_uv"></span>
</span>
</span>
<span class="post-meta-item" id="busuanzi_container_site_pv">
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
<span class="site-pv" title="Total Views">
<span id="busuanzi_value_site_pv"></span>
</span>
</span>
</div>
<div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a>
</div>
</div>
</footer>
<div class="back-to-top" role="button" aria-label="Back to top">
<i class="fa fa-arrow-up fa-lg"></i>
<span>0%</span>
</div>
<noscript>
<div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script class="next-config" data-name="utterances" type="application/json">{"enable":true,"repo":"hwchiu/blog-comment","issue_term":"pathname","theme":"github-light"}</script>
<script src="/js/third-party/comments/utterances.js"></script>
</body>
</html>