

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

# 使用標籤控制Lightsail資源存取
<a name="amazon-lightsail-controlling-access-using-tags"></a>

您可在 Amazon Lightsail 中使用標籤來控制對資源、請求及標籤金鑰的存取。本指南將說明如何建立 AWS Identity and Access Management (IAM) 政策，在其中指定建立或刪除 Lightsail 資源所需的索引鍵值標籤，並將政策附接至需要提出這些請求的使用者或群組。

**注意**  
欲進一步了解 Lightsail 中的標籤、可加上標籤的資源及其限制，請參閱[標籤](amazon-lightsail-tags.md)。

## 步驟 1：建立 IAM 政策
<a name="create-an-iam-policy"></a>

首先，在 IAM 主控台建立下列 IAM 政策。如需有關建立 IAM 政策的詳細資訊，請參閱 IAM 文件中的[建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)。

下列政策會限制使用者建立新的 Lightsail 資源，除非建立請求已定義 `allow` 金鑰標籤及 `true` 值。此政策也會限制使用者刪除資源，除非他們具有 `allow/true` 索引鍵值標籤。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "lightsail:Create*",
                "lightsail:TagResource",
                "lightsail:UntagResource"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:RequestTag/allow": "true"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "lightsail:Delete*",
                "lightsail:TagResource",
                "lightsail:UntagResource"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/allow": "true"
                }
            }
        }
    ]
}
```

------

下列政策會限制使用者變更索引鍵值標籤並非 `allow/false` 之資源的標籤。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "lightsail:TagResource"
            ],
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:ResourceTag/allow": "false"
                }
            }
        }
    ]
}
```

------

## 步驟 2：將政策連接至使用者或群組
<a name="attach-the-policy"></a>

建立 IAM 政策後，請將其附接至需要使用索引鍵/值組來建立 Lightsail 資源的使用者或群組。如需有關將 IAM 政策連接至使用者或群組的詳細資訊，請參閱 IAM 文件中的[新增和移除 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。