You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
IAM
ECS custom policy examples
Copy page
Download PDF
ECS custom policy examples
If the system default policies provided by the platform cannot meet your needs, you can create custom policies based on the principle of least privilege. This enables fine-grained permission control and enhances secure access by IAM identities to resources under the root account. This topic shows examples of common custom policies related to ECS instances as a reference.​
Background​
  • When creating a custom policy, you need to follow the basic structure and syntax. For details of policy element configuration, refer to Policy syntax.​
  • In the following examples, the API operation names listed under Action can be obtained from the API list.​
  • For the TRN format of ECS-authorized resources, refer to Resources.​
Custom policy examples​
Allow access to resources under specified projects​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:DescribeInstances"​
],​
"Resource": [​
"trn:ecs:*:210005****:instance/*",​
"trn:iam::210005****:project/default"​
]​
}​
]​
}​
​
This policy allows viewing instances belonging to the "default" project under Account 210005****. When you grant authorizations by project, you need to select a project scope in addition to the existing authorization policy, thereby restricting permissions to the specified project.​
Deny ECS instance deletion​
tip​
Deny takes precedence over Allow. If an identity has Deny permissions for certain actions, the Allow permissions for those same actions will not take effect. To resolve this, remove the relevant Deny statements or modify them to Allow.​
Deny all instance deletion​
​
{​
"Statement": [​
{​
"Effect": "Deny",​
"Action": [​
"ecs:DeleteInstance",​
"ecs:DeleteInstances"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Deny ECS resource deletion for instances with IDs i-yczzpbpgqoqc6ilc**** and i-yczv4tg64gqc6iks**** under account 200000000X​
​
{​
"Statement": [​
{​
"Effect": "Deny",​
"Action": [​
"ecs:Delete*"​
],​
"Resource": [​
"trn:ecs:*:200000000X:instance/i-yczzpbpgqoqc6ilc****,i-yczv4tg64gqc6iks****"​
]​
}​
]​
}​
​
Allow ECS instance creation​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:RunInstances"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Deny ECS instance information change​
​
{​
"Statement": [​
{​
"Effect": "Deny",​
"Action": [​
"ecs:ModifyInstanceAttribute"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Restrict ECS instance access​
Allow actions on the ECS instance with the ID i-yczzpbpgqoqc6ilc**** under account 200000000X​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:*"​
],​
"Resource": [​
"trn:ecs:*:200000000X:instance/i-yczzpbpgqoqc6ilc****"​
]​
}​
]​
}​
​
Allow ECS resource viewing​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:Describe*"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Access ECS from a specific IP address​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:*"​
],​
"Resource": [​
"*"​
],​
"Condition": {​
"IpAddress": {​
"volc:SourceIp": [​
"210.22.XX.XX"​
]​
}​
}​
}​
]​
}​
​
Only ECS resources with the tag key "ecs" and a condition value of "use" can be accessed​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:*"​
],​
"Resource": [​
"*"​
],​
"Condition": {​
"StringEquals": {​
"volc:ResourceTag/ecs": [​
"use"​
]​
}​
}​
}​
]​
}​
​
Allow access to tag feature​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:CreateTags",​
"ecs:DeleteTags",​
"ecs:DescribeTags"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Deny key pair deletion​
​
{​
"Statement": [​
{​
"Effect": "Deny",​
"Action": [​
"ecs:DeleteKeyPairs"​
],​
"Resource": [​
"*"​
]​
}​
]​
}​
​
Only allow O&M orchestration tasks to apply for, query, and associate Elastic IPs (EIPs)​
​
​
{​
"Statement":[​
{​
"Effect":"Allow",​
"Action":[​
"vpc:AllocateEipAddress",​
"vpc:DescribeEipAddresses",​
"vpc:AssociateEipAddress"​
],​
"Resource":["*"]​
}​
]​
}​
​
Restrict the use of target custom commands to the specified IAM users​
​
{​
"Statement": [​
{​
"Effect": "Allow",​
"Action": [​
"ecs:Describe*",​
"ecs:ModifyCommand",​
"ecs:InvokeCommand"​
],​
"Resource": [​
"trn:ecs:cn-beijing:210001*****:command/cmd-ycn5dc9qf9l8j0v*****",​
"trn:ecs:cn-beijing:210001*****:command/cmd-tsx0gy9rslp90k3z*****"​
]​
}​
]​
}​
​
​
Last updated: 2026.10.29 14:11:45