Yi Tse Wu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `NTU Master Thesis` # AWS 設定 以下說明五個 AWS 服務,AWS IoT Core、IoT Analytics、S3、Lambda、Quicksight 的設定方法 ## IoT Core 按下 IoT Core 中的**建立實物**,照著上面的指示,建立名稱為 THING 的實物(該名稱是舉例,實際上可自由命名實物名稱)。接著,會有將政策 (Policy) 連接到憑證的指示文字出現。此時,為了讓實物有權限能上傳、儲存、刪除資料,需編寫下列 Json 形式的政策並連結到該實物上,以讓 AWS 知道要給 IoT Core 哪些權限。注意,以下 Json 裡的 THING 這個單詞,會隨著實物名稱而更改,切勿直接複製貼上,否則會有 error 產生 ![](https://i.imgur.com/RqRLRiD.png) ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Connect", "Resource": [ "arn:aws:iot:us-east-1:912429886604:client/THING/*" ] }, { "Effect": "Allow", "Action": "iot:Publish", "Resource": [ "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/update", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/delete", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/get" ] }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": [ "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/update/accepted", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/delete/accepted", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/get/accepted", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/update/rejected", "arn:aws:iot:us-east-1:912429886604:topic/$aws/things/THING/shadow/name/*/delete/rejected" ] }, { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": [ "arn:aws:iot:us-east-1:912429886604:topicfilter/$aws/things/THING/shadow/name/*/update/accepted", "arn:aws:iot:us-east-1:912429886604:topicfilter/$aws/things/THING/shadow/name/*/delete/accepted", "arn:aws:iot:us-east-1:912429886604:topicfilter/$aws/things/THING/shadow/name/*/get/accepted", "arn:aws:iot:us-east-1:912429886604:topicfilter/$aws/things/THING/shadow/name/*/update/rejected", "arn:aws:iot:us-east-1:912429886604:topicfilter/$aws/things/THING/shadow/name/*/delete/rejected" ] }, { "Effect": "Allow", "Action": [ "iot:GetThingShadow", "iot:UpdateThingShadow", "iot:DeleteThingShadow" ], "Resource": [ "arn:aws:iot:us-east-1:912429886604:thing/THING/*" ] } ] } ``` 新增完實物並且連接政策後,移動到訊息路由中的規則頁面,在這邊可以設定上傳到 IoT Core 的 Json 訊息去向。本研究是將 Json 訊息傳至 IoT Analytics 中。在設定規則時,要輸入以下 SQL 陳述式,以讓任何名稱的 deviceShadow 訊息都能傳到 IoT Analytics 中。注意,以下 SQL 指令的 THING 這個單詞,會隨著實物名稱而更改,切勿直接複製貼上 ```sql SELECT state.reported.* FROM "$aws/things/THING/shadow/name/+/update/accepted" ``` 如下圖所示,這是本研究使用的其中一個規則設定頁面 ![](https://i.imgur.com/82xsOiR.png) ## IoT Analytics 在 IoT Analytics 的頁面,要設定頻道、管道、資料存放區和資料集,方能順利地將資料送到 IoT Analytics 的資料存放區。有資料在資料存放區後,才能在下圖的資料集頁面中,設定 SQL 查詢指令,以生成 CSV 的檔案供程式下載或前端 Quicksight 抓取,SQL 指令如下 : ![](https://i.imgur.com/7uQODCX.png) ```sql SELECT Arktomato_Multi_PR_01_Temp, Arktomato_Multi_PR_01_Mois, Arktomato_Multi_PR_01_Time, Arktomato_Multi_PR_01_SD_Card_SDData, Arktomato_Multi_PR_02_Temp, Arktomato_Multi_PR_02_Mois, Arktomato_Multi_PR_02_Time, Arktomato_Multi_PR_02_SD_Card_SDData, Arktomato_Multi_PR_03_Temp, Arktomato_Multi_PR_03_Mois, Arktomato_Multi_PR_03_Time, Arktomato_Multi_PR_03_SD_Card_SDData, Arktomato_Multi_PR_04_Temp, Arktomato_Multi_PR_04_Mois, Arktomato_Multi_PR_04_Time, Arktomato_Multi_PR_04_SD_Card_SDData, Arktomato_Multi_TEROS_05_Temp, Arktomato_Multi_TEROS_05_VWC, Arktomato_Multi_TEROS_05_EC, Arktomato_Multi_TEROS_05_Time, Arktomato_Multi_TEROS_05_SD_Card_SDData, Arktomato_Multi_TEROS_06_Temp, Arktomato_Multi_TEROS_06_VWC, Arktomato_Multi_TEROS_06_EC, Arktomato_Multi_TEROS_06_Time, Arktomato_Multi_TEROS_06_SD_Card_SDData FROM arktomato_field_datastore ``` 以上指令完成後,便能抓取來自資料存放區內的各項資料,並將之成為 CSV 檔案中的各個 Coloums。後續若要在本地機器中分析資料,可以直接從 AWS 頁面載 CSV 資料下來、或是使用 AWS 的函式庫 boto3 下載資料 ## S3 (要有資料才能用,名稱:pestnodeimage) 於本研究當中,採用 S3 來儲存圖片形式的資料 (補充 : 圖片是藉由 boto3 上傳到 S3 中的)。值得注意的是,當 S3 物件要公開的話,也要寫 Json 形式的檔案,讓其他 AWS 服務能讀取儲存在 S3 中的物件。以下檔案中的 Resource 會隨著檔名結構有所更改,切勿直接複製貼上 ```json { "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": [ "arn:aws:s3:::pestnodeimgdata/Lab405Rpi/video.png", "arn:aws:s3:::pestnodeimgdata/Shangsheng_Field/Node_01/Node_01.jpg", "arn:aws:s3:::pestnodeimgdata/Shangsheng_Field/Node_02/Node_02.jpg" ] } ] } ``` 下方便是更改 S3 物件權限的地方,需進到許可子分頁中才能看到相關設定 ![](https://i.imgur.com/S0bq8ek.png) ## Lambda Lambda 的程式放在實驗室雲端資料夾中,可查看之: https://bblab.bime.ntu.edu.tw/cloud/apps/files/?dir=/2_405_students/Master%20Students/R109/%E5%90%B3%E4%B9%99%E6%BE%A4/VMSM%E8%A8%AD%E8%A8%88/%E8%BB%9F%E9%AB%94/AWS%20Lambda&fileid=4081517#filestexteditor *P.S.若要新增 Quicksight (UI介面) 和 Line 警示,才會用到 Lambda* AWS Lambda 是一種無伺服器運算的服務,按下建立函式的按鈕後,能選擇程式語言的環境。以下舉 Python 為例子。見下方的程式碼, lambda_handler 是 Lambda 的主函數,類似 C++ 的 main()。本研究在 lambda_handler 中,以 boto3 的 API 去下載位於 IoT Analytics 和 S3 的感測器與圖片資料,並使用 AWS Layer 擴展出的 pandas 和 numpy 函數庫,對下載下來的資料做處理和分析 ```python def lambda_handler(event, context): ... ... ... return 1 ``` 編寫完 lambda_handler 函數後,如下圖,可以於組態頁面中的一般組態,更改該函數使用的記憶體量、處理的上限時間。並且,也能根據使用情況,設置 API Gateway、EventBridge 等觸發函數的方法 ![](https://i.imgur.com/lqdNPZt.png) 最後,值得注意的是,若要在 lambda_handler 中下載來自 IoT Analytics 和 S3 的感測器與圖片資料,需要給 Lambda 的 IAM 角色足夠的權限去讀取和寫入資料,否則執行 Lambda 函數時會有錯誤產生。以下是本研究在 IAM 服務中,某個 Lambda 角色的 JSON 權限設定檔,可供讀者參考。注意,以下 Json 檔案中的 Resource 會隨個人定義的檔案名稱而有所不同,切勿直接複製貼上 ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "logs:CreateLogGroup", "Resource": "arn:aws:logs:us-east-1:912429886604:*" }, { "Effect": "Allow", "Action": [ "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": [ "arn:aws:logs:us-east-1:912429886604:log-group:/aws/lambda/Process_Envi_Data:*" ] }, { "Effect": "Allow", "Action": "iotanalytics:GetDatasetContent", "Resource": [ "arn:aws:iotanalytics:us-east-1:912429886604:dataset/shangsheng_field_dataset", "arn:aws:iotanalytics:us-east-1:912429886604:dataset/arktomato_field_dataset" ] }, { "Effect": "Allow", "Action": [ "s3:*" ], "Resource": [ "arn:aws:s3:::lambdaprocessdata", "arn:aws:s3:::lambdaprocessdata/*" ] } ] } ``` 如下圖所示,需要點入紅色框框內的連結,才會看到能修改權限的 Json 編輯器 ![](https://i.imgur.com/V7ZC5V4.png) ## Quicksight 在 AWS Quicksight 中,可以直覺地拉動圖塊、選擇資料集的屬性資料,進而編寫出精緻的 UI 介面 但是,在拉動圖塊,需要先匯入資料。於本研究中,匯入資料的方式有兩種 * 直接點選來自 IoT Analytics 的資料 * 透過上傳 Json 形式的檔案,將儲存在 S3 的 CSV 檔案連結到 Quicksight 中。其中,該 CSV 檔是透過 Lambda 處理過後的資料,處理包括最大、最小、平均值運算等等 第二種的 Json 格式如下所示。注意,以下 Json 檔案中的 URIs 會隨個人定義的檔案名稱而有所不同,切勿直接複製貼上 ```json { "fileLocations": [ { "URIs": [ "https://lambdaprocessdata.s3.amazonaws.com/ShangSheng_Soil_Uniformity_Data" ] } ], "globalUploadSettings": { "format": "CSV" } } ``` 如下圖所示,點選 S3 作為資料輸入後,會有頁面要求你上傳 Json 形式的檔案。該檔案的形式就是上方的 Json 格式編寫而成的檔案 ![](https://i.imgur.com/x55yXau.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully