Contoh AWS FIStemplate percobaan - AWS Layanan Injeksi Kesalahan

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Contoh AWS FIStemplate percobaan

Jika Anda menggunakan AWS FISAPIatau alat baris perintah untuk membuat template percobaan, Anda dapat membuat template di JavaScript Object Notation ()JSON. Untuk informasi selengkapnya tentang komponen templat eksperimen, lihatAWS FISkomponen template percobaan.

Untuk membuat eksperimen menggunakan salah satu contoh templat, simpan ke JSON file (misalnya,my-template.json), ganti nilai placeholder di italics dengan nilai Anda sendiri, dan kemudian jalankan create-experiment-templateperintah berikut.

aws fis create-experiment-template --cli-input-json file://my-template.json

Hentikan EC2 instance berdasarkan filter

Contoh berikut menghentikan semua EC2 instance Amazon yang berjalan di Wilayah tertentu dengan tag yang ditentukan dalam yang ditentukanVPC. Ini restart mereka setelah dua menit.

{ "tags": { "Name": "StopEC2InstancesWithFilters" }, "description": "Stop and restart all instances in us-east-1b with the tag env=prod in the specified VPC", "targets": { "myInstances": { "resourceType": "aws:ec2:instance", "resourceTags": { "env": "prod" }, "filters": [ { "path": "Placement.AvailabilityZone", "values": ["us-east-1b"] }, { "path": "State.Name", "values": ["running"] }, { "path": "VpcId", "values": [ "vpc-aabbcc11223344556"] } ], "selectionMode": "ALL" } }, "actions": { "StopInstances": { "actionId": "aws:ec2:stop-instances", "description": "stop the instances", "parameters": { "startInstancesAfterDuration": "PT2M" }, "targets": { "Instances": "myInstances" } } }, "stopConditions": [ { "source": "aws:cloudwatch:alarm", "value": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:alarm-name" } ], "roleArn": "arn:aws:iam::111122223333:role/role-name" }

Hentikan sejumlah EC2 instans tertentu

Contoh berikut menghentikan tiga contoh dengan tag yang ditentukan. AWS FISmemilih instance tertentu untuk berhenti secara acak. Ini memulai ulang contoh ini setelah dua menit.

{ "tags": { "Name": "StopEC2InstancesByCount" }, "description": "Stop and restart three instances with the specified tag", "targets": { "myInstances": { "resourceType": "aws:ec2:instance", "resourceTags": { "env": "prod" }, "selectionMode": "COUNT(3)" } }, "actions": { "StopInstances": { "actionId": "aws:ec2:stop-instances", "description": "stop the instances", "parameters": { "startInstancesAfterDuration": "PT2M" }, "targets": { "Instances": "myInstances" } } }, "stopConditions": [ { "source": "aws:cloudwatch:alarm", "value": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:alarm-name" } ], "roleArn": "arn:aws:iam::111122223333:role/role-name" }

Jalankan pra-konfigurasi AWS FISSSMdokumen

Contoh berikut menjalankan injeksi CPU kesalahan selama 60 detik pada EC2 instance yang ditentukan menggunakan pra-konfigurasi AWS FISSSMdokumen, AWSFIS-Jalankan- CPU -Stres. AWS FISmemonitor percobaan selama dua menit.

{ "tags": { "Name": "CPUStress" }, "description": "Run a CPU fault injection on the specified instance", "targets": { "myInstance": { "resourceType": "aws:ec2:instance", "resourceArns": ["arn:aws:ec2:us-east-1:111122223333:instance/instance-id"], "selectionMode": "ALL" } }, "actions": { "CPUStress": { "actionId": "aws:ssm:send-command", "description": "run cpu stress using ssm", "parameters": { "duration": "PT2M", "documentArn": "arn:aws:ssm:us-east-1::document/AWSFIS-Run-CPU-Stress", "documentParameters": "{\"DurationSeconds\": \"60\", \"InstallDependencies\": \"True\", \"CPU\": \"0\"}" }, "targets": { "Instances": "myInstance" } } }, "stopConditions": [ { "source": "aws:cloudwatch:alarm", "value": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:alarm-name" } ], "roleArn": "arn:aws:iam::111122223333:role/role-name" }

Jalankan runbook Otomasi yang telah ditentukan

Contoh berikut menerbitkan notifikasi ke Amazon SNS menggunakan runbook yang disediakan oleh Systems Manager, AWS -P. ublishSNSNotification Peran harus memiliki izin untuk mempublikasikan pemberitahuan ke SNS topik yang ditentukan.

{ "description": "Publish event through SNS", "stopConditions": [ { "source": "none" } ], "targets": { }, "actions": { "sendToSns": { "actionId": "aws:ssm:start-automation-execution", "description": "Publish message to SNS", "parameters": { "documentArn": "arn:aws:ssm:us-east-1::document/AWS-PublishSNSNotification", "documentParameters": "{\"Message\": \"Hello, world\", \"TopicArn\": \"arn:aws:sns:us-east-1:111122223333:topic-name\"}", "maxDuration": "PT1M" }, "targets": { } } }, "roleArn": "arn:aws:iam::111122223333:role/role-name" }

APITindakan throttle pada EC2 instance dengan peran target IAM

Contoh berikut membatasi 100% API panggilan yang ditentukan dalam definisi tindakan untuk API panggilan yang dibuat oleh IAM peran yang ditentukan dalam definisi target.

catatan

Jika Anda ingin menargetkan EC2 instans yang merupakan anggota grup Auto Scaling, gunakan tindakan aws:ec2asg-insufficient-instance-capacity: -error, dan targetkan berdasarkan grup Auto Scaling sebagai gantinya. Untuk informasi selengkapnya, lihat .

{ "tags": { "Name": "ThrottleEC2APIActions" }, "description": "Throttle the specified EC2 API actions on the specified IAM role", "targets": { "myRole": { "resourceType": "aws:iam:role", "resourceArns": ["arn:aws:iam::111122223333:role/role-name"], "selectionMode": "ALL" } }, "actions": { "ThrottleAPI": { "actionId": "aws:fis:inject-api-throttle-error", "description": "Throttle APIs for 5 minutes", "parameters": { "service": "ec2", "operations": "DescribeInstances,DescribeVolumes", "percentage": "100", "duration": "PT2M" }, "targets": { "Roles": "myRole" } } }, "stopConditions": [ { "source": "aws:cloudwatch:alarm", "value": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:alarm-name" } ], "roleArn": "arn:aws:iam::111122223333:role/role-name" }

Uji CPU stres pod di klaster Kubernetes

Contoh berikut menggunakan Chaos Mesh untuk menguji stress pod di cluster Amazon EKS Kubernetes selama satu menit. CPU

{ "description": "ChaosMesh StressChaos example", "targets": { "Cluster-Target-1": { "resourceType": "aws:eks:cluster", "resourceArns": [ "arn:aws:eks:arn:aws::111122223333:cluster/cluster-id" ], "selectionMode": "ALL" } }, "actions": { "TestCPUStress": { "actionId": "aws:eks:inject-kubernetes-custom-resource", "parameters": { "maxDuration": "PT2M", "kubernetesApiVersion": "chaos-mesh.org/v1alpha1", "kubernetesKind": "StressChaos", "kubernetesNamespace": "default", "kubernetesSpec": "{\"selector\":{\"namespaces\":[\"default\"],\"labelSelectors\":{\"run\":\"nginx\"}},\"mode\":\"all\",\"stressors\": {\"cpu\":{\"workers\":1,\"load\":50}},\"duration\":\"1m\"}" }, "targets": { "Cluster": "Cluster-Target-1" } } }, "stopConditions": [{ "source": "none" }], "roleArn": "arn:aws:iam::111122223333:role/role-name", "tags": {} }

Contoh berikut menggunakan Lakmus untuk stress test pod di cluster Amazon EKS Kubernetes selama satu menit. CPU

{ "description": "Litmus CPU Hog", "targets": { "MyCluster": { "resourceType": "aws:eks:cluster", "resourceArns": [ "arn:aws:eks:arn:aws::111122223333:cluster/cluster-id" ], "selectionMode": "ALL" } }, "actions": { "MyAction": { "actionId": "aws:eks:inject-kubernetes-custom-resource", "parameters": { "maxDuration": "PT2M", "kubernetesApiVersion": "litmuschaos.io/v1alpha1", "kubernetesKind": "ChaosEngine", "kubernetesNamespace": "litmus", "kubernetesSpec": "{\"engineState\":\"active\",\"appinfo\":{\"appns\":\"default\",\"applabel\":\"run=nginx\",\"appkind\":\"deployment\"},\"chaosServiceAccount\":\"litmus-admin\",\"experiments\":[{\"name\":\"pod-cpu-hog\",\"spec\":{\"components\":{\"env\":[{\"name\":\"TOTAL_CHAOS_DURATION\",\"value\":\"60\"},{\"name\":\"CPU_CORES\",\"value\":\"1\"},{\"name\":\"PODS_AFFECTED_PERC\",\"value\":\"100\"},{\"name\":\"CONTAINER_RUNTIME\",\"value\":\"docker\"},{\"name\":\"SOCKET_PATH\",\"value\":\"/var/run/docker.sock\"}]},\"probe\":[]}}],\"annotationCheck\":\"false\"}" }, "targets": { "Cluster": "MyCluster" } } }, "stopConditions": [{ "source": "none" }], "roleArn": "arn:aws:iam::111122223333:role/role-name", "tags": {} }