InitUser

class aws_cdk.aws_ec2.InitUser(user_name, *, groups=None, home_dir=None, user_id=None)

Bases: InitElement

Create Linux/UNIX users and to assign user IDs.

Users are created as non-interactive system users with a shell of /sbin/nologin. This is by design and cannot be modified.

Not supported for Windows systems.

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc
# instance_type: ec2.InstanceType
# machine_image: ec2.IMachineImage


ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,

    # Showing the most complex setup, if you have simpler requirements
    # you can use `CloudFormationInit.fromElements()`.
    init=ec2.CloudFormationInit.from_config_sets(
        config_sets={
            # Applies the configs below in this order
            "default": ["yumPreinstall", "config"]
        },
        configs={
            "yum_preinstall": ec2.InitConfig([
                # Install an Amazon Linux package using yum
                ec2.InitPackage.yum("git")
            ]),
            "config": ec2.InitConfig([
                # Create a JSON file from tokens (can also create other files)
                ec2.InitFile.from_object("/etc/stack.json", {
                    "stack_id": Stack.of(self).stack_id,
                    "stack_name": Stack.of(self).stack_name,
                    "region": Stack.of(self).region
                }),

                # Create a group and user
                ec2.InitGroup.from_name("my-group"),
                ec2.InitUser.from_name("my-user"),

                # Install an RPM from the internet
                ec2.InitPackage.rpm("http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/r/rubygem-git-1.5.0-2.el8.noarch.rpm")
            ])
        }
    ),
    init_options=ec2.ApplyCloudFormationInitOptions(
        # Optional, which configsets to activate (['default'] by default)
        config_sets=["default"],

        # Optional, how long the installation is expected to take (5 minutes by default)
        timeout=Duration.minutes(30),

        # Optional, whether to include the --url argument when running cfn-init and cfn-signal commands (false by default)
        include_url=True,

        # Optional, whether to include the --role argument when running cfn-init and cfn-signal commands (false by default)
        include_role=True
    )
)
Parameters:
  • user_name (str) –

  • groups (Optional[Sequence[str]]) – A list of group names. The user will be added to each group in the list. Default: the user is not associated with any groups.

  • home_dir (Optional[str]) – The user’s home directory. Default: assigned by the OS

  • user_id (Union[int, float, None]) – A user ID. The creation process fails if the user name exists with a different user ID. If the user ID is already assigned to an existing user the operating system may reject the creation request. Default: assigned by the OS

Attributes

element_type

Returns the init element type for this element.

Static Methods

classmethod from_name(user_name, *, groups=None, home_dir=None, user_id=None)

Create a user from user name.

Parameters:
  • user_name (str) –

  • groups (Optional[Sequence[str]]) – A list of group names. The user will be added to each group in the list. Default: the user is not associated with any groups.

  • home_dir (Optional[str]) – The user’s home directory. Default: assigned by the OS

  • user_id (Union[int, float, None]) – A user ID. The creation process fails if the user name exists with a different user ID. If the user ID is already assigned to an existing user the operating system may reject the creation request. Default: assigned by the OS

Return type:

InitUser