

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

# 範例：從 S3 儲存貯體執行 AWS PCS 的其他指令碼
<a name="working-with_ec2-user-data_s3"></a>

 在啟動範本`"userData"`中提供此指令碼做為 的值。如需詳細資訊，請參閱[使用 AWS PCS 的 Amazon EC2 使用者資料](working-with_ec2-user-data.md)。

下列使用者資料指令碼使用 **cloud-config** 從 S3 儲存貯體匯入指令碼，並在啟動時在節點群組執行個體上執行。如需詳細資訊，請參閱 *cloud-init 文件*中的[使用者資料格式](https://cloudinit.readthedocs.io/en/latest/explanation/format.html)。

將下列值取代為您自己的詳細資訊：
+ *amzn-s3-demo-bucket* – 您的帳戶可讀取的 S3 儲存貯體名稱。
+ *object-key* – 要匯入之指令碼的 S3 物件金鑰。這包括指令碼的名稱及其在儲存貯體資料夾結構中的位置。例如 `scripts/script.sh`。如需詳細資訊，請參閱《[Amazon Simple Storage Service 使用者指南》中的使用資料夾在 Amazon S3 主控台中組織物件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-folders.html)。 **
+ *shell* – 用來執行指令碼的 Linux shell，例如 `bash`。

```
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

runcmd:
- aws s3 cp s3://amzn-s3-demo-bucket/object-key /tmp/script.sh
- /usr/bin/shell /tmp/script.sh

--==MYBOUNDARY==--
```

節點群組的 IAM 執行個體描述檔必須能夠存取 儲存貯體。下列 IAM 政策是上述使用者資料指令碼中儲存貯體的範例。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket",
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        }
    ]
}
```

------