我該如何在 Quick Sight 儀表板上使用來自私有 Amazon S3 儲存貯體的圖像?
3 分的閱讀內容
0
我想在 Amazon Quick Sight 儀表板上使用來自私有 Amazon Simple Storage Service (Amazon S3) 儲存貯體的圖像。
解決方法
若要在 Quick Sight 儀表板或報告上使用私有 Amazon S3 儲存貯體中的影像,請使用 AWS Lambda API 或 Amazon CloudFront 主控台。
Lambda API
若要使用 Lambda API,請建立 Lambda 函式,然後建立 Amazon API Gateway 觸發程序。
建立 Lambda 函式
請完成以下步驟:
- 開啟 Amazon S3 console (Amazon S3 主控台)。
- 在導覽窗格中,選擇 Buckets (儲存貯體),然後選取您的儲存貯體。
- 選擇 Upload (上傳)。
- 將影像以 .jpg 格式上傳至儲存貯體。
- 執行以下命令來建立 Lambda 函式:
**注意:**將 S3 BUCKET NAME 和 downloaded_s3_object 替換為您的資訊。Lambda AWS Identity and Access Management (IAM) 角色必須具備從 S3 儲存貯體取得物件的權限。對於 Lambda 函式,將 Runtime (執行時期) 設為 Python 3.9。import boto3 import base64 def lambda_handler(event, context): s3 = boto3.client("s3") downloaded_s3_object = s3.get_object(Bucket="S3 BUCKET NAME", Key="Image.jpg") return base64.b64encode(downloaded_s3_object["Body"].read()) - 選擇 Deploy (部署)。
建立 API Gateway 觸發程序
請完成以下步驟:
- 開啟 API Gateway console (API Gateway 主控台)。
- 在導覽窗格中,選擇 APIs (API),然後選擇 Create API (建立 API)。
- 在 REST API 下,選擇 Build (建置)。
- 在 Create REST API (建立 REST API) 頁面的 API details (API 詳細資訊) 下,選擇 New API (新 API),然後輸入以下資訊:
輸入 API 的名稱,然後選擇 Create API (建立 API)。
(選用) 輸入 API 的描述。
對於 API endpoint type (API 端點類型),選取 Regional (區域)。然後選擇 Create API (建立 API)。 - 在 Resources (資源) 頁面的 Methods (方法) 下,選擇 Create method (建立方法)。
- 在 Create method (建立方法) 頁面上,輸入以下資訊:
對於 Method type (方法類型),選擇 GET。
對於 Integration type (整合類型),選擇 Lambda function (Lambda 函式)。
對於 Lambda function (Lambda 函式),選擇 AWS 區域和您的 Lambda 函式。 - 選擇 Create method (建立方法)。
- 在 Resources (資源) 頁面的 Method request settings (方法請求設定) 下,選擇 Edit (編輯)。
- 在 Edit method request (編輯方法請求) 頁面的 HTTP request headers (HTTP 請求標頭) 下,選擇 Add header (新增標頭)。
- 對於 Name (名稱),輸入 Content-Type,然後選擇 Save (儲存)。
- 在 Resources (資源) 頁面的 Integration response (整合回應) 下,選擇 Edit (編輯)。
- 在 Response details (回應詳細資訊) 下,對於 Content handling (內容處理),選擇 Convert to binary (轉換為二進位)。
- 選擇 Save (儲存)。
- 部署您的 API。
**注意:**如需更多資訊,請參閱在 API Gateway 中設定 REST API 的階段。 - 在 Stages (階段) 頁面的 Stage details (階段詳細資訊) 下,記下調用網址。例如,https://1a2bc3d456.execute-api.region.amazonaws.com/test。
- 開啟 Quick Suite console (Quick Suite 主控台)。
- 在導覽窗格中,選擇 Analyses (分析),然後選取您要新增影像的分析。
- 在 Visuals (視覺效果) 選單上,選擇 Custom visual content (自訂視覺效果內容)。
- 選擇 Customize visual (自訂視覺效果)。
- 在 Properties (屬性) 窗格的 Customize content (自訂內容) 下,輸入調用網址。
- 開啟 Show as image (顯示為影像) 選項,然後選擇 Apply (套用)。
API Gateway 會傳回影像的 base64 字串。Quick Sight 洞察編輯器會使用 API 的網址來顯示影像。
CloudFront 主控台
請完成以下步驟:
- 開啟 CloudFront console (CloudFront 主控台)。
- 在導覽窗格中,選擇 Distributions (發佈項目),然後選擇 Create distribution (建立發佈項目)。
- 在 Create distribution (建立發佈項目) 頁面上,輸入以下資訊:
對於 Origin domain (原始網域),輸入原始伺服器的網域名稱。
對於 Origin access (原始存取),選擇 Origin access control settings (recommended) (原始存取控制設定 (建議))。
對於 Origin access control (原始存取控制),選擇 Create new OAC (建立新的 OAC),然後選擇 Create (建立)。 - 在 Web Application Firewall (WAF) 下,選取 Do not enable security protections (不啟用安全防護)。
- 選擇 Create distribution (建立發佈項目)。
- 在 Distribution details (發佈項目詳細資訊) 頁面上,記下發佈項目網域名稱。例如,d2icdkfpjckhwg.cloufront.net。
- 在「需要更新 S3 儲存貯體政策」訊息中,選擇 Copy policy (複製政策)。
- 開啟 Amazon S3 console (Amazon S3 主控台)。
- 在 General purpose buckets (一般用途儲存貯體) 下,選取託管原始網域內容的儲存貯體。
- 在 Bucket details (儲存貯體詳細資訊) 頁面的 Permissions (權限) 下,選擇 Edit (編輯)。
- 輸入政策,然後選擇 Save changes (儲存變更)。
- 在 Bucket details (儲存貯體詳細資訊) 頁面的 Objects (物件) 下,選取物件。
- 在 Object details (物件詳細資訊) 頁面上,記下 S3 URI。例如,s3://your-bucket-name/your_image.png。
- 在新的瀏覽器索引標籤中,輸入 S3 URI。例如,d2icdkfpjckhwg.cloufront.net/your_image.png。
- 在 Quick Sight 儀表板的 Properties (屬性) 下,選擇 Visual (視覺效果) 區段,然後在網址欄位中輸入自訂 URI。
- 選擇 Apply (套用)。
- 語言
- 中文 (繁體)

AWS 官方已更新 1 年前
沒有評論
相關內容
已提問 2 年前
已提問 2 年前
已提問 2 年前
已提問 1 年前
AWS 官方已更新 8 個月前