MultipartBody

class aws_cdk.aws_ec2.MultipartBody

Bases: object

The base class for all classes which can be used as MultipartUserData.

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 render_body_part()

Render body part as the string.

Subclasses should not add leading nor trailing new line characters (r n)

Return type:

List[str]

Attributes

CLOUD_BOOTHOOK = 'text/cloud-boothook; charset="utf-8"'
SHELL_SCRIPT = 'text/x-shellscript; charset="utf-8"'

Static Methods

classmethod from_raw_body(*, content_type, body=None, transfer_encoding=None)

Constructs the raw MultipartBody using specified body, content type and transfer encoding.

When transfer encoding is specified (typically as Base64), it’s caller responsibility to convert body to Base64 either by wrapping with Fn.base64 or by converting it by other converters.

Parameters:
  • content_type (str) – Content-Type header of this part. Some examples of content types: - text/x-shellscript; charset="utf-8" (shell script) - text/cloud-boothook; charset="utf-8" (shell script executed during boot phase) For Linux shell scripts use text/x-shellscript.

  • body (Optional[str]) – The body of message. Default: undefined - body will not be added to part

  • transfer_encoding (Optional[str]) – Content-Transfer-Encoding header specifying part encoding. Default: undefined - body is not encoded

Return type:

MultipartBody

classmethod from_user_data(user_data, content_type=None)

Constructs the new MultipartBody wrapping existing UserData. Modification to UserData are reflected in subsequent renders of the part.

For more information about content types see MultipartBodyOptions.contentType.

Parameters:
  • user_data (UserData) – user data to wrap into body part.

  • content_type (Optional[str]) – optional content type, if default one should not be used.

Return type:

MultipartBody