Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan CreateDeployment dengan CLI
Contoh kode berikut menunjukkan cara menggunakanCreateDeployment.
- CLI
-
- AWS CLI
-
Contoh 1: Untuk membuat CodeDeploy penerapan menggunakan platform komputasi EC2 /On-premise
create-deploymentContoh berikut membuat penyebaran dan mengaitkannya dengan akun pengguna. AWSaws deploy create-deployment \ --application-nameWordPress_App\ --deployment-config-nameCodeDeployDefault.OneAtATime\ --deployment-group-nameWordPress_DG\ --description"My demo deployment"\ --s3-locationbucket=amzn-s3-demo-bucket,bundleType=zip,eTag=dd56cfdEXAMPLE8e768f9d77fEXAMPLE,key=WordPressApp.zipOutput:
{ "deploymentId": "d-A1B2C3111" }Contoh 2: Untuk membuat CodeDeploy penerapan menggunakan platform komputasi Amazon ECS
create-deploymentContoh berikut menggunakan dua file berikut untuk menyebarkan layanan Amazon ECS.Isi
create-deployment.jsonfile:{ "applicationName": "ecs-deployment", "deploymentGroupName": "ecs-deployment-dg", "revision": { "revisionType": "S3", "s3Location": { "bucket": "ecs-deployment-bucket", "key": "appspec.yaml", "bundleType": "YAML" } } }File itu, pada gilirannya, mengambil file berikut
appspec.yamldari bucket S3 yang disebut.ecs-deployment-bucketversion: 0.0 Resources: - TargetService: Type: AWS::ECS::Service Properties: TaskDefinition: "arn:aws:ecs:region:123456789012:task-definition/ecs-task-def:2" LoadBalancerInfo: ContainerName: "sample-app" ContainerPort: 80 PlatformVersion: "LATEST"Perintah:
aws deploy create-deployment \ --cli-input-jsonfile://create-deployment.json\ --regionus-east-1Output:
{ "deploymentId": "d-1234ABCDE" }Untuk informasi selengkapnya, lihat CreateDeployment di dalam Referensi API AWS CodeDeploy .
-
Untuk detail API, lihat CreateDeployment
di Referensi AWS CLI Perintah.
-
- PowerShell
-
- Alat untuk PowerShell V4
-
Contoh 1: Contoh ini membuat penyebaran baru untuk grup aplikasi dan penyebaran yang ditentukan dengan konfigurasi penerapan dan revisi aplikasi yang ditentukan.
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3Output:
d-ZHROG7UEXContoh 2: Contoh ini menunjukkan cara menentukan grup tag EC2 instance yang harus diidentifikasi oleh sebuah instance agar dapat disertakan dalam lingkungan pengganti untuk blue/green penerapan.
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3 -Ec2TagSetList @(@{Key="key1";Type="KEY_ONLY"},@{Key="Key2";Type="KEY_AND_VALUE";Value="Value2"}),@(@{Key="Key3";Type="VALUE_ONLY";Value="Value3"})Output:
d-ZHROG7UEX-
Untuk detail API, lihat CreateDeploymentdi Referensi Alat AWS untuk PowerShell Cmdlet (V4).
-
- Alat untuk PowerShell V5
-
Contoh 1: Contoh ini membuat penyebaran baru untuk grup aplikasi dan penyebaran yang ditentukan dengan konfigurasi penerapan dan revisi aplikasi yang ditentukan.
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3Output:
d-ZHROG7UEXContoh 2: Contoh ini menunjukkan cara menentukan grup tag EC2 instance yang harus diidentifikasi oleh sebuah instance agar dapat disertakan dalam lingkungan pengganti untuk blue/green penerapan.
New-CDDeployment -ApplicationName MyNewApplication -S3Location_Bucket amzn-s3-demo-bucket -S3Location_BundleType zip -DeploymentConfigName CodeDeployDefault.OneAtATime -DeploymentGroupName MyNewDeploymentGroup -IgnoreApplicationStopFailures $True -S3Location_Key aws-codedeploy_linux-master.zip -RevisionType S3 -Ec2TagSetList @(@{Key="key1";Type="KEY_ONLY"},@{Key="Key2";Type="KEY_AND_VALUE";Value="Value2"}),@(@{Key="Key3";Type="VALUE_ONLY";Value="Value3"})Output:
d-ZHROG7UEX-
Untuk detail API, lihat CreateDeploymentdi Referensi Alat AWS untuk PowerShell Cmdlet (V5).
-