終止支援通知:在 2025 年 12 月 15 日, AWS 將結束對 的支援 AWS IoT Analytics。2025 年 12 月 15 日之後,您將無法再存取 AWS IoT Analytics 主控台或 AWS IoT Analytics 資源。如需詳細資訊,請參閱AWS IoT Analytics 終止支援。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
步驟 2:匯出先前擷取的資料
對於先前擷取並存放於 的資料 AWS IoT Analytics,您需要將其匯出至 Amazon S3。若要簡化此程序,您可以使用 AWS CloudFormation 範本來自動化整個資料匯出工作流程。您可以使用指令碼進行部分 (時間範圍型) 資料擷取。

AWS CloudFormation 將資料匯出至 Amazon S3 的 範本
上圖說明使用 AWS CloudFormation 範本在相同資料 AWS IoT Analytics 存放區中建立資料集的程序,以根據時間戳記進行選擇。這可讓使用者在所需的時間範圍內擷取特定資料點。此外,也會建立內容交付規則,將資料匯出至 Amazon S3 儲存貯體。
以下程序說明步驟。
-
準備 AWS CloudFormation 範本並將其儲存為 YAML 檔案。例如
migrate-datasource.yaml
。# Cloudformation Template to migrate an AWS IoT Analytics datastore to an external dataset AWSTemplateFormatVersion: 2010-09-09 Description: Migrate an AWS IoT Analytics datastore to an external dataset Parameters: DatastoreName: Type: String Description: The name of the datastore to migrate. AllowedPattern: ^[a-zA-Z0-9_]+$ TimeRange: Type: String Description: | This is an optional argument to split the source data into multiple files. The value should follow the SQL syntax of WHERE clause. E.g. WHERE DATE(Item_TimeStamp) BETWEEN '09/16/2010 05:00:00' and '09/21/2010 09:00:00'. Default: '' MigrationS3Bucket: Type: String Description: The S3 Bucket where the datastore will be migrated to. AllowedPattern: (?!(^xn--|.+-s3alias$))^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$ MigrationS3BucketPrefix: Type: String Description: The prefix of the S3 Bucket where the datastore will be migrated to. Default: '' AllowedPattern: (^([a-zA-Z0-9.\-_]*\/)*$)|(^$) Resources: # IAM Role to be assumed by the AWS IoT Analytics service to access the external dataset DatastoreMigrationRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: iotanalytics.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: AllowAccessToExternalDataset PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - s3:GetBucketLocation - s3:GetObject - s3:ListBucket - s3:ListBucketMultipartUploads - s3:ListMultipartUploadParts - s3:AbortMultipartUpload - s3:PutObject - s3:DeleteObject Resource: - !Sub arn:aws:s3:::${MigrationS3Bucket} - !Sub arn:aws:s3:::${MigrationS3Bucket}/${MigrationS3BucketPrefix}* # This dataset that will be created in the external S3 Export MigratedDataset: Type: AWS::IoTAnalytics::Dataset Properties: DatasetName: !Sub ${DatastoreName}_generated Actions: - ActionName: SqlAction QueryAction: SqlQuery: !Sub SELECT * FROM ${DatastoreName} ${TimeRange} ContentDeliveryRules: - Destination: S3DestinationConfiguration: Bucket: !Ref MigrationS3Bucket Key: !Sub ${MigrationS3BucketPrefix}${DatastoreName}/!{iotanalytics:scheduleTime}/!{iotanalytics:versionId}.csv RoleArn: !GetAtt DatastoreMigrationRole.Arn RetentionPeriod: Unlimited: true VersioningConfiguration: Unlimited: true
-
決定需要匯出資料的資料 AWS IoT Analytics 存放區。針對本指南,我們將使用名為 的範例資料存放區
iot_analytics_datastore
。 -
建立或識別要匯出資料的 Amazon S3 儲存貯體。針對本指南,我們將使用 儲存
iot-analytics-export
貯體。 -
建立 AWS CloudFormation 堆疊。
導覽至 https://https://console.aws.amazon.com/cloudformation
。 按一下建立堆疊,然後選取使用新資源 (標準)。
上傳
migrate-datasource.yaml
檔案。
-
輸入堆疊名稱並提供下列參數:
DatastoreName:您要遷移 AWS IoT Analytics 的資料存放區名稱。
MigrationS3Bucket:存放遷移資料的 Amazon S3 儲存貯體。
MigrationS3BucketPrefix (選用):Amazon S3 儲存貯體的字首。
TimeRange (選用) :用於篩選匯出資料的
SQL WHERE
子句,允許根據指定的時間範圍將來源資料分割成多個檔案。
-
在設定堆疊選項畫面上按一下下一步。
-
選取核取方塊以確認建立 IAM 資源,然後按一下提交。
-
檢閱事件索引標籤上的堆疊建立是否完成。
-
成功完成堆疊後,導覽至 AWS IoT Analytics → 資料集以檢視遷移的資料集。
-
選取產生的資料集,然後按一下立即執行以匯出資料集。
-
您可以在資料集的內容索引標籤上檢視內容。
-
最後,在 Amazon S3 主控台中開啟 iot-analytics-export 儲存貯體,以檢閱匯出的內容。