Example: Run additional scripts for AWS PCS from an S3 bucket - AWS PCS

Example: Run additional scripts for AWS PCS from an S3 bucket

Provide this script as the value of "userData" in your launch template. For more information, see Working with Amazon EC2 user data.

This script uses cloud-config to import a script from an S3 bucket and run it on node group instances at launch. For more information, see the User data formats in the cloud-init documentation.

Replace the following values in this script with your own details:

  • my-bucket-name – The name of an S3 bucket your account can read from.

  • path – The path relative to the S3 bucket root.

  • shell – The Linux shell to use to run the script, such as 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://my-bucket-name/path /tmp/script.sh - /usr/bin/shell /tmp/script.sh --==MYBOUNDARY==--

The IAM instance profile for the node group must have access to the bucket. The following IAM policy is an example for the bucket in the user data script above.

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