aws-cdk-lib.aws_ec2.InitPackage

class InitPackage

LanguageType name
.NETAmazon.CDK.AWS.EC2.InitPackage
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#InitPackage
Javasoftware.amazon.awscdk.services.ec2.InitPackage
Pythonaws_cdk.aws_ec2.InitPackage
TypeScript (source)aws-cdk-lib » aws_ec2 » InitPackage

Extends InitElement

A package to be installed during cfn-init time.

Example

declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;

new ec2.Instance(this, 'Instance', {
  vpc,
  instanceType,
  machineImage,

  // Showing the most complex setup, if you have simpler requirements
  // you can use `CloudFormationInit.fromElements()`.
  init: ec2.CloudFormationInit.fromConfigSets({
    configSets: {
      // Applies the configs below in this order
      default: ['yumPreinstall', 'config'],
    },
    configs: {
      yumPreinstall: new ec2.InitConfig([
        // Install an Amazon Linux package using yum
        ec2.InitPackage.yum('git'),
      ]),
      config: new ec2.InitConfig([
        // Create a JSON file from tokens (can also create other files)
        ec2.InitFile.fromObject('/etc/stack.json', {
          stackId: Stack.of(this).stackId,
          stackName: Stack.of(this).stackName,
          region: Stack.of(this).region,
        }),

        // Create a group and user
        ec2.InitGroup.fromName('my-group'),
        ec2.InitUser.fromName('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'),
      ]),
    },
  }),
  initOptions: {
    // Optional, which configsets to activate (['default'] by default)
    configSets: ['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)
    includeUrl: true,

    // Optional, whether to include the --role argument when running cfn-init and cfn-signal commands (false by default)
    includeRole: true,
  },
});

Initializer (protected)

super(type: string, versions: string[], packageName?: string, serviceHandles?: InitServiceRestartHandle[])

Parameters

  • type string
  • versions string[]
  • packageName string
  • serviceHandles InitServiceRestartHandle[]

Properties

NameTypeDescription
elementTypestringReturns the init element type for this element.

elementType

Type: string

Returns the init element type for this element.

Methods

NameDescription
protected renderPackageVersions()
static apt(packageName, options?)Install a package using APT.
static msi(location, options?)Install an MSI package from an HTTP URL or a location on disk.
static python(packageName, options?)Install a package from PyPI.
static rpm(location, options?)Install an RPM from an HTTP URL or a location on disk.
static rubyGem(gemName, options?)Install a package from RubyGems.
static yum(packageName, options?)Install a package using Yum.

protected renderPackageVersions()

protected renderPackageVersions(): any

Returns

  • any

static apt(packageName, options?)

public static apt(packageName: string, options?: NamedPackageOptions): InitPackage

Parameters

  • packageName string
  • options NamedPackageOptions

Returns

  • InitPackage

Install a package using APT.


static msi(location, options?)

public static msi(location: string, options?: LocationPackageOptions): InitPackage

Parameters

  • location string
  • options LocationPackageOptions

Returns

  • InitPackage

Install an MSI package from an HTTP URL or a location on disk.


static python(packageName, options?)

public static python(packageName: string, options?: NamedPackageOptions): InitPackage

Parameters

  • packageName string
  • options NamedPackageOptions

Returns

  • InitPackage

Install a package from PyPI.


static rpm(location, options?)

public static rpm(location: string, options?: LocationPackageOptions): InitPackage

Parameters

  • location string
  • options LocationPackageOptions

Returns

  • InitPackage

Install an RPM from an HTTP URL or a location on disk.


static rubyGem(gemName, options?)

public static rubyGem(gemName: string, options?: NamedPackageOptions): InitPackage

Parameters

  • gemName string
  • options NamedPackageOptions

Returns

  • InitPackage

Install a package from RubyGems.


static yum(packageName, options?)

public static yum(packageName: string, options?: NamedPackageOptions): InitPackage

Parameters

  • packageName string
  • options NamedPackageOptions

Returns

  • InitPackage

Install a package using Yum.