UserData
- class aws_cdk.aws_ec2.UserData
Bases:
object
Instance User Data.
- ExampleMetadata:
infused
Example:
multipart_user_data = ec2.MultipartUserData() commands_user_data = ec2.UserData.for_linux() multipart_user_data.add_user_data_part(commands_user_data, ec2.MultipartBody.SHELL_SCRIPT, True) # Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa. multipart_user_data.add_commands("touch /root/multi.txt") commands_user_data.add_commands("touch /root/userdata.txt")
Methods
- abstract add_commands(*commands)
Add one or more commands to the user data.
- Parameters:
commands (
str
) –- Return type:
None
- abstract add_execute_file_command(*, file_path, arguments=None)
Adds commands to execute a file.
- Parameters:
file_path (
str
) – The path to the file.arguments (
Optional
[str
]) – The arguments to be passed to the file. Default: No arguments are passed to the file.
- Return type:
None
- abstract add_on_exit_commands(*commands)
Add one or more commands to the user data that will run when the script exits.
- Parameters:
commands (
str
) –- Return type:
None
- abstract add_s3_download_command(*, bucket, bucket_key, local_file=None, region=None)
Adds commands to download a file from S3.
- Parameters:
bucket (
IBucket
) – Name of the S3 bucket to download from.bucket_key (
str
) – The key of the file to download.local_file (
Optional
[str
]) – The name of the local file. Default: Linux - /tmp/bucketKey Windows - %TEMP%/bucketKeyregion (
Optional
[str
]) – The region of the S3 Bucket (needed for access via VPC Gateway). Default: none
- Return type:
str
- Returns:
: The local path that the file will be downloaded to
- abstract add_signal_on_exit_command(resource)
Adds a command which will send a cfn-signal when the user data script ends.
- Parameters:
resource (
Resource
) –- Return type:
None
- abstract render()
Render the UserData for use in a construct.
- Return type:
str
Static Methods
- classmethod custom(content)
Create a userdata object with custom content.
- Parameters:
content (
str
) –- Return type:
- classmethod for_linux(*, shebang=None)
Create a userdata object for Linux hosts.
- Parameters:
shebang (
Optional
[str
]) – Shebang for the UserData script. Default: “#!/bin/bash”- Return type:
- classmethod for_operating_system(os)
- Parameters:
os (
OperatingSystemType
) –- Return type: