<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Veck on Medium]]></title>
        <description><![CDATA[Stories by Veck on Medium]]></description>
        <link>https://medium.com/@veckhsiao?source=rss-a8ebfde339ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*d4ke4iF1gZ_-B0_-.jpeg</url>
            <title>Stories by Veck on Medium</title>
            <link>https://medium.com/@veckhsiao?source=rss-a8ebfde339ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:23:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@veckhsiao/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GitHub Copilot on Visual Studio Code]]></title>
            <link>https://veckhsiao.medium.com/github-copilot-on-visual-studio-code-6808b2404ea6?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6808b2404ea6</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 14:42:10 GMT</pubDate>
            <atom:updated>2024-07-12T14:42:10.106Z</atom:updated>
            <content:encoded><![CDATA[<p>因為寫了一段 for-loop，覺得有點醜，所以想試試看請 AI 幫我改，雖然已經有安裝 Codeium，但想說 GitHub 的 code base 多，想試試看 GitHub Copilot，個人使用一個月 10 美金也還好，就訂閱下去了。</p><p>訂閱好後，我想在 Visual Studio Code 中使用，除了要安裝 GitHub Copilot 的套件，接著還要登入 GitHub 帳號，然後點選 VSCode 左邊的「聊天」選項。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/55/1*NrE6wRVPd1LD8JA4GjKB2w.png" /><figcaption>聊天</figcaption></figure><p>依據提示，可以直接在檔案中使用內嵌聊天，我先把想請 AI 修改的地方反白，然後就會跳出聊天視窗，沒有跳出來的話，也可以點選旁邊出現的橘色燈泡選擇。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BukZAu7NDtMNfXzqT8B6w.png" /><figcaption>輸入希望修改的方式(e.g. 優化)</figcaption></figure><p>執行輸入的 prompt 後，就會開始動作，修正/建議過程中會一步一步變動，感覺很像在看教學。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2Zk7NOWXSHz0U1rVcrFGw.png" /><figcaption>原本的邏輯 (左) 建議修改後的新邏輯(右)</figcaption></figure><p>建議的修改完成後，按下「接受」，就可以套用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6bhtl53n9BAAfX6bx4qS_A.png" /><figcaption>套用建議修改的邏輯</figcaption></figure><p>個人心得是覺得蠻厲害的，但就如同 Copilot 自己說的，畢竟是 AI，很可能出錯，建議還是要做驗證跑跑看。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6808b2404ea6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple M1 上使用 Podman 遇到的問題]]></title>
            <link>https://veckhsiao.medium.com/apple-m1-%E4%B8%8A%E4%BD%BF%E7%94%A8-podman-%E9%81%87%E5%88%B0%E7%9A%84%E5%95%8F%E9%A1%8C-96a7a448fb8b?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/96a7a448fb8b</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 15:11:03 GMT</pubDate>
            <atom:updated>2023-12-20T15:11:03.678Z</atom:updated>
            <content:encoded><![CDATA[<p>會發現這個問題其實是我在用 mongodb 的 atlas cli 做 local deployment 時，發現卡在這一步很久(hanging)，都沒有下面的 output 喔!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*3eLEACD9EPrC0CoIpT1n9w.png" /></figure><p>然後才一路查到問題是在 podman，修正 podman 啟動的 vm 後，就可以成功 deploy atlas 了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*JsSbu4kkxRKfVLpJg4grEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*26vf5YfTyvy81PIjJ-NJmw.png" /></figure><p>問題與解決</p><ol><li>啟動 vm 時一直遇到啟動不了的錯誤，vm 砍也砍不掉，一直卡在 currently starting</li></ol><p>作法：ps auxwww | grep podman 然後 kill 那個 process 強制重啟 podman (edited)</p><p><a href="https://sanityrover.slack.com/archives/C06AZUP7R5H/p1703078693617209">9:24</a></p><p>2. 重啟後可以砍掉了，重新 podman machine init 後，可以建立，但是當要 podman machine start podman-machine-default 時，出現以下錯誤</p><pre>➜  podman machine start podman-machine-default<br>Starting machine &quot;podman-machine-default&quot;<br>Waiting for VM ...<br>Error: qemu exited unexpectedly with exit code 1, stderr: qemu-system-aarch64: VCPU supports less PA bits (36) than requested by the memory map (40)</pre><p>這也是 M1 的問題！但是與其花幾萬塊更新 iMac 到 M3，還不如想辦法透過修改啟動設定或是改本機源碼解決問題<br>雖然網路上的討論不多，但果然最後找到方法了<br>要去修改這個檔案：</p><pre>vim ~/.config/containers/podman/machine/qemu/podman-machine-default.json</pre><p>將 “-M” 下一行的 “virt,highmem=on” 改成 “virt,highmem=off”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*N5FhVYnIWlAGUKr_SP6zaQ.png" /></figure><p>然後再重新啟動一次，就可以了！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-QZzDDZxJkffTlxQu6pJg.png" /></figure><p>確認啟動狀態以變更為 currently runnning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*5Mb2vHlM70_8AgxSVCf9Wg@2x.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96a7a448fb8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[apple/swift-evolution 上關於 guard 的有趣討論]]></title>
            <link>https://veckhsiao.medium.com/apple-swift-evolution-%E4%B8%8A%E9%97%9C%E6%96%BC-guard-%E7%9A%84%E6%9C%89%E8%B6%A3%E8%A8%8E%E8%AB%96-6ba11a3966d2?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ba11a3966d2</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Wed, 18 May 2022 06:53:33 GMT</pubDate>
            <atom:updated>2022-05-18T07:09:42.835Z</atom:updated>
            <content:encoded><![CDATA[<p>不久前在使用 guard 的時候，因為忘記加上 return，發生了常見的低級錯誤：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VoWMm6qcFOj1zuR1bUM2_g.png" /></figure><p>什麼！guard 一定要 return 喔，不能直接跳轉就好？</p><p>查看到彼得潘大大的討論文:</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E6%AA%A2%E6%9F%A5%E6%A2%9D%E4%BB%B6%E6%98%AF%E5%90%A6%E6%88%90%E7%AB%8B-%E4%B8%8D%E6%88%90%E7%AB%8B%E5%B0%B1%E9%9B%A2%E9%96%8B%E7%9A%84-guard-else-9650f3ac8e04">檢查條件是否成立，不成立就離開的 guard else</a></p><blockquote><em>else { } 的程式執行後，必須離開 guard 所在區塊，如此才不會繼續往下執行條件成立時要做的事。就像剛剛的例子，我們利用 return 離開 function motherSay。</em></blockquote><p>奇怪，那怎麼不設計成 guard 的 else 中預設最後面就會自動 return，不需要 explicitly 寫出 return?</p><p>我想說查看一下 <a href="https://github.com/apple/swift-evolution/blob/77cb9392aa550c9313c73aa9b95be3b6508b6c83/commonly_proposed.md#control-flow-closures-optional-binding-and-error-handling">swift-evolution</a> 有沒有關於這個設計理念的說明，果然被我找到了。</p><ul><li>infer return for omitted guard body</li></ul><blockquote><em>It has been proposed many times to allow omission of the </em><em>guard body for the sake of brevity.</em></blockquote><p>而官方的說明是：</p><blockquote><em>However, a core principle of Swift is to make control flow explicit and visible. ….. Implicit returns would violate this principle</em></blockquote><p>我的解讀是之所以不採用 infer 的方式忽略掉 return，應該是因為要遵從 swift 的設計理念，讓程式碼好讀懂。</p><p>另外還有一個我也有想過的項目：</p><ul><li>rename gaurd to unless</li></ul><blockquote><em>It is a common request that </em><em>guard be renamed </em><em>unless….People requesting this change argue that </em><em>guard is simply a logically inverted </em><em>if statement, and therefore </em><em>unless is a more obvious keyword.</em></blockquote><p>不適合的理由：</p><blockquote><em>However, such requests stem from a fundamental misunderstanding of the functionality provided by </em><em>guard. Unlike </em><em>if, </em><em>guard </em>enforces<em> that the code within its curly braces provides an early exit from the codepath.</em></blockquote><p>意思大概是說，雖然 unless 在邏輯上是 if 的反義詞，但是通常語意上 unless COND (then) { …} 這樣是「<strong>希望要做後面 then 的部分，除非 COND 成立」</strong></p><p>而 guard COND else { … }，語意上是：「有 COND 嗎？沒有，你給我離開」(就像警衛攔查可疑人物一樣)，是一個希望<strong>提早排除</strong>(early exit) 的概念。</p><p>以上如果有解讀錯誤的地方，歡迎留言給我～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ba11a3966d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[昨天出去跑步時發生兩耳只有一耳接得上，回來後電腦也是，而且會有左邊接上右邊就斷，反之亦然，藍芽關掉或是忘記此裝置後重新連線(閃白燈)都沒用，甚至發生左邊接上 iPhone 右邊接上 MacBook…]]></title>
            <link>https://veckhsiao.medium.com/%E6%98%A8%E5%A4%A9%E5%87%BA%E5%8E%BB%E8%B7%91%E6%AD%A5%E6%99%82%E7%99%BC%E7%94%9F%E5%85%A9%E8%80%B3%E5%8F%AA%E6%9C%89%E4%B8%80%E8%80%B3%E6%8E%A5%E5%BE%97%E4%B8%8A-%E5%9B%9E%E4%BE%86%E5%BE%8C%E9%9B%BB%E8%85%A6%E4%B9%9F%E6%98%AF-%E8%80%8C%E4%B8%94%E6%9C%83%E6%9C%89%E5%B7%A6%E9%82%8A%E6%8E%A5%E4%B8%8A%E5%8F%B3%E9%82%8A%E5%B0%B1%E6%96%B7-%E5%8F%8D%E4%B9%8B%E4%BA%A6%E7%84%B6-%E8%97%8D%E8%8A%BD%E9%97%9C%E6%8E%89%E6%88%96%E6%98%AF%E5%BF%98%E8%A8%98%E6%AD%A4%E8%A3%9D%E7%BD%AE%E5%BE%8C%E9%87%8D%E6%96%B0%E9%80%A3%E7%B7%9A-%E9%96%83%E7%99%BD%E7%87%88-%E9%83%BD%E6%B2%92%E7%94%A8-%E7%94%9A%E8%87%B3%E7%99%BC%E7%94%9F%E5%B7%A6%E9%82%8A%E6%8E%A5%E4%B8%8A-iphone-%E5%8F%B3%E9%82%8A%E6%8E%A5%E4%B8%8A-macbook-97fc118c415f?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/97fc118c415f</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[airpods]]></category>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Wed, 17 Mar 2021 20:58:13 GMT</pubDate>
            <atom:updated>2021-03-17T20:58:13.460Z</atom:updated>
            <content:encoded><![CDATA[<p>昨天出去跑步時發生兩耳只有一耳接得上，回來後電腦也是，而且會有左邊接上右邊就斷，反之亦然，藍芽關掉或是忘記此裝置後重新連線(閃白燈)都沒用，甚至發生左邊接上 iPhone 右邊接上 MacBook 同時兩個不同音源的現象，而且假這先讓一邊接上裝置了，這邊會時不時出現中斷或雜音干擾，就好像裝置一直試圖在重新接上另一耳。</p><p>睡前想說放棄了，起床後再上網找一下資料，這次直接只看 Apple 官網的一份技術<a href="https://support.apple.com/zh-tw/HT209463">支援文件</a>，一樣四個步驟：</p><ol><li><strong>將 AirPods 放入充電盒</strong>：關上盒蓋。等待 30 秒，然後打開盒蓋。</li><li><strong>忘記此裝置設定</strong>：在 iPhone、iPad 或 iPod touch 上，前往「設定」&gt;「藍牙」，點一下 AirPods 旁的「i」圖像。然後點一下「忘記此裝置設定」，再點一下以確認。</li><li><strong>重置 AirPods</strong>：在盒蓋打開的情況下，按住充電盒背面的設定按鈕約 15 秒，直到狀態指示燈閃爍琥珀色。</li><li><strong>重新連線 AirPods</strong>：在盒蓋打開的情況下，將 AirPods 放在靠近裝置的地方。按照裝置螢幕上的步驟操作。</li></ol><p>仔細在研究一遍發現，看到第三步這裡說的重置所需的 15 秒</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*QxW-UAM2epqJXA2E9Z6KKg.png" /></figure><p>跟第一步的 30 秒不同，稍早網路上找的其他平台資料很亂，有些只說靜置30秒再重新打開連接，有些說按 15 或 10 秒重置，這些資料都沒有說到兩個都要做，而且說按了15秒後會是<strong>琥珀色</strong>，我晚上試的時候有看到這個，但我只按了幾秒就變色，而且是變白色，我以為是我對顏色的認知錯誤，所以就直接重新連線裝置，結果還是失敗…。</p><p>這是我半信半疑，總之先照著步驟一靜置 30 秒後打開，接著忘記此裝置後，按著盒子按鈕超過 15 秒，一開始還是直接從綠色變白色</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZ4G8jnSS5RSN6hfSvHikw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_U1udnxWWogOJJdt8XHiQ.jpeg" /></figure><p>但超過 15 秒後，果然出現近似橘色的琥珀色！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ufgoht2M-OFA51uhFpFBA.jpeg" /></figure><p>然後重新連線，先嘗試iPhone，果然就恢復兩耳都同時連接有聲音了！接著再暫時關閉 iPhone的藍芽(不關閉好像無法)，改去連接 MacBook (我按到出現白色就鬆開按鈕)也恢復了！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97fc118c415f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[AWS ECS] 將建立的 EC2 instance 加入指定的 Cluster]]></title>
            <link>https://veckhsiao.medium.com/aws-ecs-%E5%B0%87%E5%BB%BA%E7%AB%8B%E7%9A%84-ec2-instance-%E5%8A%A0%E5%85%A5%E6%8C%87%E5%AE%9A%E7%9A%84-cluster-a947d950c208?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a947d950c208</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 02:37:54 GMT</pubDate>
            <atom:updated>2018-08-07T02:37:54.938Z</atom:updated>
            <content:encoded><![CDATA[<p>要使用 ECS，需要先有 Cluster，然後才在 Cluster 中建立 Containers，在 Container 中才去開 task 運行服務</p><h3><strong>Create Cluster</strong></h3><p>先到 ECS 的介面，選擇 Cluster 去建立一個新的 Cluster，Cluster name 輸入完以後可以直接建立</p><p>不填寫其他項目的話勾選 Create an empty cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhTr6YUrwfo5qUrlKfRdMw.png" /></figure><p>如此會建立一個不含任何 container instance 的 cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jhlCRNpwN07E3lau8XgxaA.png" /></figure><p>如果建立的不是 empty cluster，則預設會建立個 EC2 instance 到這個 cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uw-UYNLy_vts6u1jByPqLw.png" /></figure><p>可以發現後面也是用到 CloudFormation 來建構基礎架構</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6YLQrrnSi9eBOS23c3N-dQ.png" /></figure><h3>Launch Container Instance into cluster</h3><p><a href="http://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html">http://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html</a></p><p>這裡我們直接到 EC2 console 去建立一個 instance，其中在 Step 3: Configure Instance Details 的地方：</p><p>1. 在 IAM 選 ecsInstanceRole</p><p>2. 在下面的 Advanced Details 設定 User data</p><pre>#!/bin/bash<br>echo ECS_CLUSTER=[CLUSTER_NAME] &gt;&gt; /etc/ecs/ecs.config # 不可以寫成 ecs_config 喔！</pre><p>這邊只要一個地方寫錯，就會自動變成開到 default cluster (原本沒有 default cluster 就會自動建立一個)，而不是我們自己開的 cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*sbxYx6XCCSc7fWmgApX7KA.png" /></figure><ul><li>Windows 的話是：</li></ul><pre>shell<br>&lt;powershell&gt;<br>Import-Module ECSTools<br>Initialize-ECSAgent -Cluster ‘[CLUSTER_NAME]’ -EnableTaskIAMRole<br>&lt;/powershell&gt;</pre><p>接著就一路 launch</p><h4>NOTICE 1</h4><p>etc/ecs/ecs.confog 這是 Optimized Linux 已經開好的檔案[由安裝 ecs-init 建立)，使用別的 AMI 建立的 instance 沒有這個檔案，所以如果是其他 AMI 得話這步驟可以跳過，啟動 instance 後在 `sudo start ecs`[1] 之前再自己去建立並且填入資料</p><h4>NOTICE 2</h4><p>正常來說應該這樣就會在 Cluster 那邊見到有一個 Registered Container instances 了，但是卻沒有</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhbPnkZmUjN5RZFgse0UUA.png" /></figure><p>Troubleshooting 的方式我們可以先 ssh 進去這個 instance</p><p>照理來說應該已經註冊了</p><p>我們去看 /var/log/ecs/ecs-init.log</p><pre>bash<br>[ec2-user@ip-172–31–20–243 ~]$ cat /var/log/ecs/ecs-init.log<br>2017–11–21T09:07:12Z [INFO] Starting Amazon EC2 Container Service Agent<br>2017–11–21T09:07:14Z [INFO] Agent exited with code 1<br>2017–11–21T09:07:14Z [INFO] Container name: /ecs-agent<br>2017–11–21T09:07:14Z [INFO] Removing existing agent container ID: 3c5290616ea532736f2d8d02465b223a0d148eea4741b3453b7381f3ff563f26<br>2017–11–21T09:07:14Z [INFO] Starting Amazon EC2 Container Service Agent<br>2017–11–21T09:07:15Z [INFO] Agent exited with code 1<br>2017–11–21T09:07:15Z [INFO] Container name: /ecs-agent<br>2017–11–21T09:07:15Z [INFO] Removing existing agent container ID: 2f946d1903237e5380387032faef443e6a649e11f1066e7bceb7257420321949<br>2017–11–21T09:07:15Z [INFO] Starting Amazon EC2 Container Service Agent<br>2017–11–21T09:07:15Z [INFO] Agent exited with code 1<br>2017–11–21T09:07:15Z [INFO] Container name: /ecs-agent<br>2017–11–21T09:07:15Z [INFO] Removing existing agent container ID: 7d68f5125d14e73b820ce1eeef48f933c564e6ced416512ce7728ee61154ce2c<br>2017–11–21T09:07:15Z [INFO] Starting Amazon EC2 Container Service Agent<br>2017–11–21T09:07:16Z [INFO] Agent exited with code 1<br>2017–11–21T09:07:16Z [INFO] Container name: /ecs-agent<br>2017–11–21T09:07:16Z [INFO] Removing existing agent container ID: 8f69f81fa411317e28864da8a536b031cc2cc1bfbc6936400eb8e8b44abed603<br>2017–11–21T09:07:16Z [INFO] Starting Amazon EC2 Container Service Agent<br>.<br>.<br>.<br></pre><p>可以發現一直是以 code 1 結束 (return 0 才是正常結束)，接著我們去看 agent log：</p><pre>$ [ec2-user@ip-172–31–20–243 ~]$ cat /var/log/ecs/ecs-agent.log.2017–11–21–09<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:50Z [INFO] Registering Instance with ECS<br>2017–11–21T09:11:50Z [ERROR] Could not register: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:50Z [CRITICAL] Could not create cluster: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:50Z [ERROR] Error registering: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:51Z [INFO] Loading configuration<br>2017–11–21T09:11:51Z [INFO] Loading state! module=”statemanager”<br>2017–11–21T09:11:51Z [INFO] Event stream ContainerChange start listening…<br>2017–11–21T09:11:51Z [WARN] Error getting valid credentials (AKID ): NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:51Z [INFO] Registering Instance with ECS<br>2017–11–21T09:11:51Z [ERROR] Could not register: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:51Z [CRITICAL] Could not create cluster: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>2017–11–21T09:11:51Z [ERROR] Error registering: NoCredentialProviders: no valid providers in chain. Deprecated.<br>For verbose messaging see aws.Config.CredentialsChainVerboseErrors<br>.<br>.<br>.</pre><p>一直都是 CredntialsChainVerboseErrors，就知道是權限沒有給，要到 EC2 去 Attach IAM Role `ecsInstancerole`</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v2xmKp0u6DrSS8S_HJNZdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kyony99_5VF8gcImjmPwnQ.png" /></figure><p>attach 後 cluster 那邊馬上就會更新了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-0EB-2KwXB2GHbb9n18ug.png" /></figure><h4>NOTICE 3</h4><p>如果是用一般的 AMI 起的 EC2 instance，到了 attach IAM role 完還是會沒有出現在 ECS cluster 中，這就是為什麼推薦使用 ECS optimized AMI 的原因</p><p>EC2 instance 要成為 Container instance 跑在 ECS 能管得到的 cluster 上，需要再 instance 中安裝 ECS agent，因為這個 AMI 已經安裝好 ECS agent，這樣你就不需要自己安裝 agent 了</p><p>**Use non-ECS optimized Amazon Linux AMI 起 Instance 加入 Cluster 完整步驟**</p><p>參考 Install ECS agent (both Amazon Linux or non-Amazon Linux) — <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-install.html">https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-install.html</a></p><p>1. 以一般方式起 Instance<br>2. 到 EC2 console 將 ecsInstanceRole 這個 IAM policy attach 到這個 instance<br>3. 連線進入這個 EC2 instance<br>4. sudo yum install -y ecs-init<br>5. touch /etc/ecs/ecs.config，然後 vim /etc/ecs/ecs.config 並且填入 ECS_CLUSTER=&lt;指定的 cluster name&gt;<br>6. sudo service docker start<br>7. sudo start ecs</p><h4>NOTICE 4</h4><p>Windows 的 EC2 instance 註冊到 Cluster 需要一段時間 (5~10 min)</p><h4>ecsInstanceRole IAM Role</h4><pre>{<br> “Version”: “2012–10–17”,<br> “Statement”: [<br> {<br> “Effect”: “Allow”,<br> “Action”: [<br> “ecs:CreateCluster”,<br> “ecs:DeregisterContainerInstance”,<br> “ecs:DiscoverPollEndpoint”,<br> “ecs:Poll”,<br> “ecs:RegisterContainerInstance”,<br> “ecs:StartTelemetrySession”,<br> “ecs:Submit*”,<br> “ecr:GetAuthorizationToken”,<br> “ecr:BatchCheckLayerAvailability”,<br> “ecr:GetDownloadUrlForLayer”,<br> “ecr:BatchGetImage”,<br> “logs:CreateLogStream”,<br> “logs:PutLogEvents”<br> ],<br> “Resource”: “*”<br> }<br> ]<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a947d950c208" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Ruby on Rails] Rails Puma + Nginx 的組合]]></title>
            <link>https://veckhsiao.medium.com/ruby-on-rails-rails-puma-nginx-%E7%9A%84%E7%B5%84%E5%90%88-a2d1965c4529?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2d1965c4529</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 02:22:15 GMT</pubDate>
            <atom:updated>2018-08-07T02:22:15.367Z</atom:updated>
            <content:encoded><![CDATA[<p>首先要認識一下兩者分別是什麼東西：</p><p>* Puma 是一個專為 Rails 設計的高併發 web server<br>* Nginx 是一個廣泛使用的 reverse proxy<br>這個時候可以去查一下什麼事 reverse proxy，就可以發現一張圖說明了兩者之間的關係</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*5ujcUGqYUEkSWNi1OMFpHg.png" /></figure><p>所謂的反向代理，是在 server-side 根據 client-side 的 request，向後端的 web server 取得資源，然後再將這些資源 response 給 client-side</p><p>另外所謂的前向代理，通常是在 client-side 的軟體，例如瀏覽器會代替 client web page (program)去向CDN請求資源</p><p>使用後端代理伺服器的好處是，假設你有很多個 web server，都統一要由單一入口給 client-side 存取，則可以把存取的工作交給 reverse proxy，例如：</p><p>Web Server:</p><p>* Home Page Web Server<br>* Forum Web Server<br>* Wiki Web Server</p><p>然後你的客戶會連線到 <a href="http://www.my.domain.com/">www.my.domain.com</a>，此時應該存取 Home Page Web Server，但當他連線到 <a href="http://www.my.domain.com/forum">www.my.domain.com/forum</a> 時，應該要存取 Forum Web Server，可是如果把你的網域綁定到 Home Page Web Server，就無法另外連線到不同伺服器了，因此可以改用反向代理伺服器，把網域綁定到這台機器上，當反向代理判斷是要存取 Home Page，就會由他向那台伺服器請求資源，而要存取 Forum 時，就另外再向論壇的伺服器請求資源</p><p>另外，反向代理伺服器還有一些對於網站應用程式來說有很大幫助的功能，例如 load balancing、auto-scaling、failover 等</p><p>load balancing 會在流量大增的時候進行分流的動作，例如你有多台 forum web server，平時每天流量上萬，為了確保伺服器能夠穩定運作，不會因為短時間的存取量太大導致伺服器處理不及而癱瘓，就可以設定將一部分的存取流量導向 standby 的那台伺服器</p><p>auto-scaling 則是可以為你正在服務的伺服器自動依據目前的流量或運算量，最大化可以分配的資源，簡單來說，你有一台伺服器的記憶體有 32GB，分配給網頁伺服器的使用量只有 2GB，如果你的網頁服務需要大量運算(例如線上資料處理或機器學習)，很有可能短時間內就把 2GB用完了，因此你可以設定當監測到記憶體快要用罄，系統會自動配置更多的記憶體來應付突發的運算量</p><p>failover 則是為了免除網站服務最擔心的事 — 中斷服務(downtime)，你的伺服器很有可能被 DDoS 攻擊，或是程式有 bug，使用者不小心觸發導致伺服器掛了，這個時候假如你有一台 standby 的伺服器，有設定好 failover 功能，則會在監控到主要伺服器中斷服務的時候，立刻將存取要求導向那台 standby 的伺服器，縮短 downtime 的時間</p><p>說到 DDoS 攻擊，load balancing 或其他相關功能也可以在監控到瞬間變大的流量時，自動將(不正常)流量導向其他地方，就有專門的業者，是提供流量接收的服務，讓一些容易被 DDoS 攻擊的網站服務公司將流量導像他們的伺服器，這個功能的設定也可以在反向代理完成</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2d1965c4529" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[OpenStack] 透過 DevStack 在 AWS EC2 Linux 上安裝 OpenStack]]></title>
            <link>https://veckhsiao.medium.com/openstack-%E9%80%8F%E9%81%8E-devstack-%E5%9C%A8-aws-ec2-linux-%E4%B8%8A%E5%AE%89%E8%A3%9D-openstack-3649714f887?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/3649714f887</guid>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 02:21:06 GMT</pubDate>
            <atom:updated>2018-08-07T02:21:06.181Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Create a EC2 instance and login</li><li>Create a stack user</li></ol><pre>$ sudo useradd -s /bin/bash -d /opt/stack -m stack<br>$ echo “stack ALL=(ALL) NOPASSWD: ALL” | sudo tee /etc/sudoers.d/stack<br>$ sudo su — stack</pre><p>3. Download DevStack</p><pre>git clone https://git.openstack.org/openstack-dev/devstack</pre><p>4. create a local.conf in project</p><pre>cd devstack<br>vim local.conf</pre><p>然後</p><pre>[[local|localrc]]<br>ADMIN_PASSWORD=secret<br>DATABASE_PASSWORD=$ADMIN_PASSWORD<br>RABBIT_PASSWORD=$ADMIN_PASSWORD<br>SERVICE_PASSWORD=$ADMIN_PASSWORD</pre><p>5. start the install: ./stack.sh. This will take a 15–20 mins. Once the installation done, all is done.</p><pre>=========================<br>DevStack Component Timing<br> (times are in seconds) <br>=========================<br>run_process 15<br>test_with_retry 2<br>apt-get-update 12<br>pip_install 287<br>osc 112<br>wait_for_service 15<br>git_timed 193<br>dbsync 23<br>apt-get 265<br> — — — — — — — — — — — — -<br>Unaccounted time 341<br>=========================<br>Total runtime 1265</pre><pre>This is your host IP address: 172.31.21.104<br>This is your host IPv6 address: ::1<br>Horizon is now available at <a href="http://172.31.21.104/dashboard">http://172.31.21.104/dashboard</a><br>Keystone is serving at <a href="http://172.31.21.104/identity/">http://172.31.21.104/identity/</a><br>The default users are: admin and demo<br>The password: secret</pre><pre>WARNING: <br>Using lib/neutron-legacy is deprecated, and it will be removed in the future</pre><pre>Services are running under systemd unit files.<br>For more information see: <br><a href="https://docs.openstack.org/devstack/latest/systemd.html">https://docs.openstack.org/devstack/latest/systemd.html</a></pre><pre>DevStack Version: queens<br>Change: 28b4be186105888b72300d27166deb771857df06 Merge “Make stackenv file visible” 2018–01–03 23:19:46 +0000<br>OS Version: Ubuntu 16.04 xenial</pre><pre>2018–01–08 05:30:33.155 | stack.sh completed in 1265 seconds.</pre><p>最後完成的訊息就這樣，就算完成安裝了</p><p>- DevStack 已經安裝好 keystone, glance, nova, cinder, neutron, 和 horizon，可以試著輸入指令看看<br>- Floating IPs will be available, guests have access to the external world.<br>- 可以試著存取 Web Interface horizon (URL 在最後的安裝訊息中)<br>- `source devstack/openrc 後會多了一個 openstack 指令來管理 DevStack<br>- You can cd `/opt/stack/tempest` and run tempest tests that have been configured to work with your devstack.<br>- You can make code changes to OpenStack and validate them.</p><h3><strong>Note for Using AWS EC2 Ubuntu 16.04</strong></h3><p>因為 EC2 是在 AWS VPC 中所建立的 VM，所以預設認知到的網卡也是區網內的 private IP，因此上面所匹配的 IP Address 173.x.x.x 是 private IP，只需要替換成這個 instance 的 Public IP 就可以成功連線到 dashboard portal 了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfQ_fdPYFgqZGhEEgKX9vA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXKJ2aopGZf39JMrRtSG0Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3649714f887" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[AWS Elastic Beanstalk] 各平台 Proxy Server List]]></title>
            <link>https://veckhsiao.medium.com/aws-elastic-beanstalk-%E5%90%84%E5%B9%B3%E5%8F%B0-proxy-server-list-3b26879d094?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b26879d094</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 02:05:47 GMT</pubDate>
            <atom:updated>2018-08-07T02:05:47.459Z</atom:updated>
            <content:encoded><![CDATA[<p>完整關於各個平台和版本採用的 Proxy Server 可以在[這裡](<a href="https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/platform-history.html">https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/platform-history.html</a>)找到：</p><h3>Nginx</h3><p>- Nodejs*<br>- Go<br>- Single Container Docker<br>- Java SE<br>- Ruby (看版本使用的 application servrer 可能是 puma 或 passenger，前者居多)</p><h3>Apache</h3><p>- Node.js*<br>- Tomcat<br>- Python<br>- PHP</p><h4>Node.js</h4><p>Node.js 預設是採用 nginx 作為 proxy server，但是官網[文件](<a href="https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html">https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html</a>)有提到可以利用 Ebextension 來設定改用 Apache 作為反向代理伺服器<br>**.ebextensions/node-settings.config**</p><pre>option_settings:<br>  aws:elasticbeanstalk:container:nodejs: <br>    NodeCommand: “npm start”<br>    ProxyServer: apache<br>    GzipCompression: true<br>  aws:elasticbeanstalk:container:nodejs:staticfiles:<br>    /images: myimages</pre><h3>IIS</h3><p>- Windows Server 上的 .NET</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b26879d094" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Puma + Nginx 的組合]]></title>
            <link>https://veckhsiao.medium.com/rails-puma-nginx-%E7%9A%84%E7%B5%84%E5%90%88-6351c5d4712e?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6351c5d4712e</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Thu, 18 Jan 2018 03:26:58 GMT</pubDate>
            <atom:updated>2018-01-18T03:43:27.678Z</atom:updated>
            <content:encoded><![CDATA[<p>Rails Puma + Nginx 的組合</p><p>首先要認識一下兩者分別是什麼東西：</p><ul><li>Puma 是一個專為 Rails 設計的高併發 <strong>web server</strong></li><li>Nginx 是一個廣泛使用的 <strong>reverse proxy</strong></li></ul><p>這個時候可以去查一下什麼事 reverse proxy，就可以發現一張圖說明了兩者之間的關係</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*oITN1VUOhzhcoltdxUh9_g.png" /><figcaption>(Source: wikipedia)</figcaption></figure><p>所謂的反向代理，是在 server-side 根據 client-side 的 request，向後端的 web server 取得資源，然後再將這些資源 response 給 client-side</p><p>另外所謂的前向代理，通常是在 client-side 的軟體，例如瀏覽器會代替 client web page (program)去向CDN請求資源</p><p>使用後端代理伺服器的好處是，假設你有很多個 web server，都統一要由單一入口給 client-side 存取，則可以把存取的工作交給 reverse proxy，例如：</p><p>Web Server:</p><ul><li>Home Page Web Server</li><li>Forum Web Server</li><li>Wiki Web Server</li></ul><p>然後你的客戶會連線到 www.my.domain.com，此時應該存取 Home Page Web Server，但當他連線到 www.my.domain.com/forum 時，應該要存取 Forum Web Server，可是如果把你的網域綁定到 Home Page Web Server，就無法另外連線到不同伺服器了，因此可以改用反向代理伺服器，把網域綁定到這台機器上，當反向代理判斷是要存取 Home Page，就會由他向那台伺服器請求資源，而要存取 Forum 時，就另外再向論壇的伺服器請求資源</p><p>另外，反向代理伺服器還有一些對於網站應用程式來說有很大幫助的功能，例如 <a href="https://en.wikipedia.org/wiki/Load_balancing_(computing)">load balancing</a>、<a href="https://en.wikipedia.org/wiki/Autoscaling">auto-scaling</a>、<a href="https://en.wikipedia.org/wiki/Failover">failover</a> 等</p><p>load balancing 會在流量大增的時候進行分流的動作，例如你有多台 forum web server，平時每天流量上萬，為了確保伺服器能夠穩定運作，不會因為短時間的存取量太大導致伺服器處理不及而癱瘓，就可以設定將一部分的存取流量導向 standby 的那台伺服器</p><p>auto-scaling 則是可以為你正在服務的伺服器自動依據目前的流量或運算量，最大化可以分配的資源，簡單來說，你有一台伺服器的記憶體有 32GB，分配給網頁伺服器的使用量只有 2GB，如果你的網頁服務需要大量運算(例如線上資料處理或機器學習)，很有可能短時間內就把 2GB用完了，因此你可以設定當監測到記憶體快要用罄，系統會自動配置更多的記憶體來應付突發的運算量</p><p>failover 則是為了免除網站服務最擔心的事 — 中斷服務(downtime)，你的伺服器很有可能被 DDoS 攻擊，或是程式有 bug，使用者不小心觸發導致伺服器掛了，這個時候假如你有一台 standby 的伺服器，有設定好 failover 功能，則會在監控到主要伺服器中斷服務的時候，立刻將存取要求導向那台 standby 的伺服器，縮短 downtime 的時間</p><p>說到 DDoS 攻擊，load balancing 或其他相關功能也可以在監控到瞬間變大的流量時，自動將(不正常)流量導向其他地方，就有專門的業者，是提供流量接收的服務，讓一些容易被 DDoS 攻擊的網站服務公司將流量導像他們的伺服器，這個功能的設定也可以在反向代理完成</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6351c5d4712e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用 S3 管理團隊成員個人檔案儲存空間]]></title>
            <link>https://veckhsiao.medium.com/%E7%94%A8-s3-%E7%AE%A1%E7%90%86%E5%9C%98%E9%9A%8A%E6%88%90%E5%93%A1%E5%80%8B%E4%BA%BA%E6%AA%94%E6%A1%88%E5%84%B2%E5%AD%98%E7%A9%BA%E9%96%93-63b16af0be0e?source=rss-a8ebfde339ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b16af0be0e</guid>
            <dc:creator><![CDATA[Veck]]></dc:creator>
            <pubDate>Tue, 03 Oct 2017 02:50:11 GMT</pubDate>
            <atom:updated>2017-10-03T02:50:11.019Z</atom:updated>
            <content:encoded><![CDATA[<h3>需求架構</h3><p>你是一間公司的 IT Manager，你被要求提供每個新來的員工一個雲端空間，你最後選擇了 Amazon S3 作為員工的雲端儲存空間，因為有以下幾個優點：</p><ol><li>公司有一組 Amazon Web Service 的帳號 vcompany，可以在此帳號下針對每個員工建立各自的 IAM account，如此可以統一管理員工的存取</li><li>可以整合內部系統(如果也是採用 AWS 服務則整合會更好)</li><li><a href="https://medium.com/@VeckHsiao/aws-s3-%E8%88%87-google-drive-%E6%96%B9%E6%A1%88%E6%AF%94%E8%BC%83-bbdb39a7a341">Pay as you use</a>.</li></ol><p>你不希望員工自己建立一個私人的 AWS 帳號來存取公司資料，且限制每個員工只能存取自己的資料夾或是指定的公共資料夾</p><p>依照需求，你會在 vcompany 的帳號下：</p><ol><li>先建立一個 bucket 叫做 employee</li><li>進入 employee，建立多個資料夾</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95ebd80bf5f648dbd5c89c3c46fd53f2/href">https://medium.com/media/95ebd80bf5f648dbd5c89c3c46fd53f2/href</a></iframe><p>因為你是希望限制資料夾層級的存取權限(folder-level permission)，所以需要透過設定 Policy 來達到目的，假設你要針對新員工 David 指定他只能存取 employee bucket 下自己的資料夾，你需要以 vcompany 的帳號進入 IAM console，建立一個 Policy 如下：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3091b73c0938d2c4c0ad91e785c6202d/href">https://medium.com/media/3091b73c0938d2c4c0ad91e785c6202d/href</a></iframe><p>假設命名此 Policy 為 s3_for_David</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vxA7np_09bPQkUnJVPrjw.png" /></figure><p>接著繼續以 vcompany 進入 IAM console，建立一個 user 叫做 David，並將剛剛建立的 s3_for_David 這個 policy attach 到這個 user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6G4s8X2ULtc143NxMH2JQ.png" /></figure><p>如此一來，登入 David 以後，雖然還是可以看到其他資料夾</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SM4K1L7d7icBxK4NFcI3Mg.png" /></figure><p>但 David 就無法進入其他 user 的資料夾了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4nAuGFuI2p9q7w0WRZN6Ng.png" /></figure><p>只能進入自己的資料夾</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q659t9NJoqX6N8gfKbONfA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b16af0be0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>