使用 的簽署者範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 的簽署者範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Signer 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 cancel-signing-profile

AWS CLI

若要刪除簽署設定檔

下列cancel-signing-profile範例會從 AWS Signer 移除現有的簽署設定檔。

aws signer cancel-signing-profile \ --profile-name MyProfile1

此命令不會產生輸出。

下列程式碼範例示範如何使用 describe-signing-job

AWS CLI

若要顯示簽署工作的詳細資訊

下列describe-signing-job範例顯示指定簽署工作的詳細資訊。

aws signer describe-signing-job \ --job-id 2065c468-73e2-4385-a6c9-0123456789abc

輸出:

{ "status": "Succeeded", "completedAt": 1568412037, "platformId": "AmazonFreeRTOS-Default", "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" }, "statusReason": "Signing Succeeded", "jobId": "2065c468-73e2-4385-a6c9-0123456789abc", "source": { "s3": { "version": "PNyFaUTgsQh5ZdMCcoCe6pT1gOpgB_M4", "bucketName": "signer-source", "key": "MyCode.rb" } }, "profileName": "MyProfile2", "signedObject": { "s3": { "bucketName": "signer-destination", "key": "signed-2065c468-73e2-4385-a6c9-0123456789abc" } }, "requestedBy": "arn:aws:iam::123456789012:user/maria", "createdAt": 1568412036 }

下列程式碼範例示範如何使用 get-signing-platform

AWS CLI

若要顯示簽署平台的詳細資訊

下列get-signing-platform範例顯示指定簽署平台的詳細資訊。

aws signer get-signing-platform \ --platform-id AmazonFreeRTOS-TI-CC3220SF

輸出:

{ "category": "AWS", "displayName": "Amazon FreeRTOS SHA1-RSA CC3220SF-Format", "target": "SHA1-RSA-TISHA1", "platformId": "AmazonFreeRTOS-TI-CC3220SF", "signingConfiguration": { "encryptionAlgorithmOptions": { "defaultValue": "RSA", "allowedValues": [ "RSA" ] }, "hashAlgorithmOptions": { "defaultValue": "SHA1", "allowedValues": [ "SHA1" ] } }, "maxSizeInMB": 16, "partner": "AmazonFreeRTOS", "signingImageFormat": { "defaultFormat": "JSONEmbedded", "supportedFormats": [ "JSONEmbedded" ] } }

下列程式碼範例示範如何使用 get-signing-profile

AWS CLI

若要顯示簽署設定檔的詳細資訊

下列get-signing-profile範例顯示指定簽署設定檔的詳細資訊。

aws signer get-signing-profile \ --profile-name MyProfile3

輸出:

{ "platformId": "AmazonFreeRTOS-TI-CC3220SF", "profileName": "MyProfile3", "status": "Active", "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetSigningProfile

下列程式碼範例示範如何使用 list-signing-jobs

AWS CLI

列出所有簽署任務

下列list-signing-jobs範例顯示帳戶所有簽署任務的詳細資訊。

aws signer list-signing-jobs

在此範例中,傳回兩個任務,一個成功,一個失敗。

{ "jobs": [ { "status": "Succeeded", "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" }, "jobId": "2065c468-73e2-4385-a6c9-0123456789abc", "source": { "s3": { "version": "PNyFaUTgsQh5ZdMCcoCe6pT1gOpgB_M4", "bucketName": "signer-source", "key": "MyCode.rb" } }, "signedObject": { "s3": { "bucketName": "signer-destination", "key": "signed-2065c468-73e2-4385-a6c9-0123456789abc" } }, "createdAt": 1568412036 }, { "status": "Failed", "source": { "s3": { "version": "PNyFaUTgsQh5ZdMCcoCe6pT1gOpgB_M4", "bucketName": "signer-source", "key": "MyOtherCode.rb" } }, "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" }, "createdAt": 1568402690, "jobId": "74d9825e-22fc-4a0d-b962-0123456789abc" } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListSigningJobs

下列程式碼範例示範如何使用 list-signing-platforms

AWS CLI

列出所有簽署平台

下列list-signing-platforms範例顯示所有可用簽署平台的詳細資訊。

aws signer list-signing-platforms

輸出:

{ "platforms": [ { "category": "AWS", "displayName": "AWS IoT Device Management SHA256-ECDSA ", "target": "SHA256-ECDSA", "platformId": "AWSIoTDeviceManagement-SHA256-ECDSA", "signingConfiguration": { "encryptionAlgorithmOptions": { "defaultValue": "ECDSA", "allowedValues": [ "ECDSA" ] }, "hashAlgorithmOptions": { "defaultValue": "SHA256", "allowedValues": [ "SHA256" ] } }, "maxSizeInMB": 2048, "partner": "AWSIoTDeviceManagement", "signingImageFormat": { "defaultFormat": "JSONDetached", "supportedFormats": [ "JSONDetached" ] } }, { "category": "AWS", "displayName": "Amazon FreeRTOS SHA1-RSA CC3220SF-Format", "target": "SHA1-RSA-TISHA1", "platformId": "AmazonFreeRTOS-TI-CC3220SF", "signingConfiguration": { "encryptionAlgorithmOptions": { "defaultValue": "RSA", "allowedValues": [ "RSA" ] }, "hashAlgorithmOptions": { "defaultValue": "SHA1", "allowedValues": [ "SHA1" ] } }, "maxSizeInMB": 16, "partner": "AmazonFreeRTOS", "signingImageFormat": { "defaultFormat": "JSONEmbedded", "supportedFormats": [ "JSONEmbedded" ] } }, { "category": "AWS", "displayName": "Amazon FreeRTOS SHA256-ECDSA", "target": "SHA256-ECDSA", "platformId": "AmazonFreeRTOS-Default", "signingConfiguration": { "encryptionAlgorithmOptions": { "defaultValue": "ECDSA", "allowedValues": [ "ECDSA" ] }, "hashAlgorithmOptions": { "defaultValue": "SHA256", "allowedValues": [ "SHA256" ] } }, "maxSizeInMB": 16, "partner": "AmazonFreeRTOS", "signingImageFormat": { "defaultFormat": "JSONEmbedded", "supportedFormats": [ "JSONEmbedded" ] } } ] }

下列程式碼範例示範如何使用 list-signing-profiles

AWS CLI

列出所有簽署設定檔

下列list-signing-profiles範例顯示帳戶所有簽署設定檔的詳細資訊。

aws signer list-signing-profiles

輸出:

{ "profiles": [ { "platformId": "AmazonFreeRTOS-TI-CC3220SF", "profileName": "MyProfile4", "status": "Active", "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" } }, { "platformId": "AWSIoTDeviceManagement-SHA256-ECDSA", "profileName": "MyProfile5", "status": "Active", "signingMaterial": { "certificateArn": "arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc" } } ] }

下列程式碼範例示範如何使用 put-signing-profile

AWS CLI

若要建立簽署設定檔

下列put-signing-profile範例會使用指定的憑證和平台建立簽署設定檔。

aws signer put-signing-profile \ --profile-name MyProfile6 \ --signing-material certificateArn=arn:aws:acm:us-west-2:123456789012:certificate/6a55389b-306b-4e8c-a95c-0123456789abc \ --platform AmazonFreeRTOS-TI-CC3220SF

輸出:

{ "arn": "arn:aws:signer:us-west-2:123456789012:/signing-profiles/MyProfile6" }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 PutSigningProfile

下列程式碼範例示範如何使用 start-signing-job

AWS CLI

啟動簽署任務

下列start-signing-job範例會在指定來源找到的程式碼上啟動簽署任務。它使用指定的設定檔來執行簽署,並將簽署的程式碼放置在指定的目的地。

aws signer start-signing-job \ --source 's3={bucketName=signer-source,key=MyCode.rb,version=PNyFaUTgsQh5ZdMCcoCe6pT1gOpgB_M4}' \ --destination 's3={bucketName=signer-destination,prefix=signed-}' \ --profile-name MyProfile7

輸出是簽署任務的 ID。

{ "jobId": "2065c468-73e2-4385-a6c9-0123456789abc" }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 StartSigningJob