class MultipartUserData
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.MultipartUserData |
Java | software.amazon.awscdk.services.ec2.MultipartUserData |
Python | aws_cdk.aws_ec2.MultipartUserData |
TypeScript (source) | @aws-cdk/aws-ec2 » MultipartUserData |
Extends
User
Mime multipart user data.
This class represents MIME multipart user data, as described in. Specifying Multiple User Data Blocks Using a MIME Multi Part Archive
Example
const bootHookConf = ec2.UserData.forLinux();
bootHookConf.addCommands('cloud-init-per once docker_options echo \'OPTIONS="${OPTIONS} --storage-opt dm.basesize=40G"\' >> /etc/sysconfig/docker');
const setupCommands = ec2.UserData.forLinux();
setupCommands.addCommands('sudo yum install awscli && echo Packages installed らと > /var/tmp/setup');
const multipartUserData = new ec2.MultipartUserData();
// The docker has to be configured at early stage, so content type is overridden to boothook
multipartUserData.addPart(ec2.MultipartBody.fromUserData(bootHookConf, 'text/cloud-boothook; charset="us-ascii"'));
// Execute the rest of setup
multipartUserData.addPart(ec2.MultipartBody.fromUserData(setupCommands));
new ec2.LaunchTemplate(this, '', {
userData: multipartUserData,
blockDevices: [
// Block device configuration rest
]
});
Initializer
new MultipartUserData(opts?: MultipartUserDataOptions)
Parameters
Methods
Name | Description |
---|---|
add | Add one or more commands to the user data. |
add | Adds commands to execute a file. |
add | Add one or more commands to the user data that will run when the script exits. |
add | Adds a part to the list of parts. |
add | Adds commands to download a file from S3. |
add | Adds a command which will send a cfn-signal when the user data script ends. |
add | Adds a multipart part based on a UserData object. |
render() | Render the UserData for use in a construct. |
Commands(...commands)
addpublic addCommands(...commands: string[]): void
Parameters
- commands
string
Add one or more commands to the user data.
ExecuteFileCommand(params)
addpublic addExecuteFileCommand(params: ExecuteFileOptions): void
Parameters
- params
Execute
File Options
Adds commands to execute a file.
OnExitCommands(...commands)
addpublic addOnExitCommands(...commands: string[]): void
Parameters
- commands
string
Add one or more commands to the user data that will run when the script exits.
Part(part)
addpublic addPart(part: MultipartBody): void
Parameters
- part
Multipart
Body
Adds a part to the list of parts.
S3DownloadCommand(params)
addpublic addS3DownloadCommand(params: S3DownloadOptions): string
Parameters
- params
S3
Download Options
Returns
string
Adds commands to download a file from S3.
SignalOnExitCommand(resource)
addpublic addSignalOnExitCommand(resource: Resource): void
Parameters
- resource
Resource
Adds a command which will send a cfn-signal when the user data script ends.
UserDataPart(userData, contentType?, makeDefault?)
addpublic addUserDataPart(userData: UserData, contentType?: string, makeDefault?: boolean): void
Parameters
- userData
User
Data - contentType
string
- makeDefault
boolean
Adds a multipart part based on a UserData object.
If makeDefault
is true, then the UserData added by this method
will also be the target of calls to the add*Command
methods on
this MultipartUserData object.
If makeDefault
is false, then this is the same as calling:
declare const multiPart: ec2.MultipartUserData;
declare const userData: ec2.UserData;
declare const contentType: string;
multiPart.addPart(ec2.MultipartBody.fromUserData(userData, contentType));
An undefined makeDefault
defaults to either:
true
if no default UserData has been set yet; orfalse
if there is no default UserData set.
render()
public render(): string
Returns
string
Render the UserData for use in a construct.