class CloudFormationInit
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.CloudFormationInit |
Java | software.amazon.awscdk.services.ec2.CloudFormationInit |
Python | aws_cdk.aws_ec2.CloudFormationInit |
TypeScript (source) | @aws-cdk/aws-ec2 » CloudFormationInit |
A CloudFormation-init configuration.
Example
declare const myBucket: s3.Bucket;
const handle = new ec2.InitServiceRestartHandle();
ec2.CloudFormationInit.fromElements(
ec2.InitFile.fromString('/etc/nginx/nginx.conf', '...', { serviceRestartHandles: [handle] }),
ec2.InitSource.fromS3Object('/var/www/html', myBucket, 'html.zip', { serviceRestartHandles: [handle] }),
ec2.InitService.enable('nginx', {
serviceRestartHandle: handle,
})
);
Methods
Name | Description |
---|---|
add | Add a config with the given name to this CloudFormationInit object. |
add | Add a config set with the given name to this CloudFormationInit object. |
attach(attachedResource, attachOptions) | Attach the CloudFormation Init config to the given resource. |
static from | Use an existing InitConfig object as the default and only config. |
static from | Build a CloudFormationInit from config sets. |
static from | Build a new config from a set of Init Elements. |
Config(configName, config)
addpublic addConfig(configName: string, config: InitConfig): void
Parameters
- configName
string
- config
Init
Config
Add a config with the given name to this CloudFormationInit object.
ConfigSet(configSetName, configNames?)
addpublic addConfigSet(configSetName: string, configNames?: string[]): void
Parameters
- configSetName
string
- configNames
string[]
Add a config set with the given name to this CloudFormationInit object.
The new configset will reference the given configs in the given order.
attach(attachedResource, attachOptions)
public attach(attachedResource: CfnResource, attachOptions: AttachInitOptions): void
Parameters
- attachedResource
Cfn
Resource - attachOptions
Attach
Init Options
Attach the CloudFormation Init config to the given resource.
As an app builder, use instance.applyCloudFormationInit()
or
autoScalingGroup.applyCloudFormationInit()
to trigger this method.
This method does the following:
- Renders the
AWS::CloudFormation::Init
object to the given resource's metadata, potentially adding aAWS::CloudFormation::Authentication
object next to it if required. - Updates the instance role policy to be able to call the APIs required for
cfn-init
andcfn-signal
to work, and potentially add permissions to download referenced asset and bucket resources. - Updates the given UserData with commands to execute the
cfn-init
script.
Config(config)
static frompublic static fromConfig(config: InitConfig): CloudFormationInit
Parameters
- config
Init
Config
Returns
Use an existing InitConfig object as the default and only config.
ConfigSets(props)
static frompublic static fromConfigSets(props: ConfigSetProps): CloudFormationInit
Parameters
- props
Config
Set Props
Returns
Build a CloudFormationInit from config sets.
Elements(...elements)
static frompublic static fromElements(...elements: InitElement[]): CloudFormationInit
Parameters
- elements
Init
Element
Returns
Build a new config from a set of Init Elements.