class InitFile
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.InitFile |
Java | software.amazon.awscdk.services.ec2.InitFile |
Python | aws_cdk.aws_ec2.InitFile |
TypeScript (source) | @aws-cdk/aws-ec2 » InitFile |
Extends
Init
Create files on the EC2 instance.
Example
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;
new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType,
machineImage,
// ...
init: ec2.CloudFormationInit.fromElements(
ec2.InitFile.fromString('/etc/my_instance', 'This got written during instance startup'),
),
signals: autoscaling.Signals.waitForAll({
timeout: Duration.minutes(10),
}),
});
Initializer (protected)
super(fileName: string, options: InitFileOptions)
Parameters
- fileName
string
- options
Init
File Options
Properties
Name | Type | Description |
---|---|---|
element | string | Returns the init element type for this element. |
elementType
Type:
string
Returns the init element type for this element.
Methods
Name | Description |
---|---|
static from | Create an asset from the given file. |
static from | Use a file from an asset at instance startup time. |
static from | Read a file from disk and use its contents. |
static from | Use a JSON-compatible object as the file content, write it to a JSON file. |
static from | Download a file from an S3 bucket at instance startup time. |
static from | Use a literal string as the file content. |
static from | Download from a URL at instance startup time. |
static symlink(fileName, target, options?) | Write a symlink with the given symlink target. |
static fromAsset(targetFileName, path, options?)
public static fromAsset(targetFileName: string, path: string, options?: InitFileAssetOptions): InitFile
Parameters
- targetFileName
string
- path
string
- options
Init
File Asset Options
Returns
Create an asset from the given file.
This is appropriate for files that are too large to embed into the template.
static fromExistingAsset(targetFileName, asset, options?)
public static fromExistingAsset(targetFileName: string, asset: Asset, options?: InitFileOptions): InitFile
Parameters
- targetFileName
string
- asset
Asset
- options
Init
File Options
Returns
Use a file from an asset at instance startup time.
static fromFileInline(targetFileName, sourceFileName, options?)
public static fromFileInline(targetFileName: string, sourceFileName: string, options?: InitFileOptions): InitFile
Parameters
- targetFileName
string
- sourceFileName
string
- options
Init
File Options
Returns
Read a file from disk and use its contents.
The file will be embedded in the template, so care should be taken to not exceed the template size.
If options.base64encoded is set to true, this will base64-encode the file's contents.
static fromObject(fileName, obj, options?)
public static fromObject(fileName: string, obj: { [string]: any }, options?: InitFileOptions): InitFile
Parameters
- fileName
string
- obj
{ [string]: any }
- options
Init
File Options
Returns
Use a JSON-compatible object as the file content, write it to a JSON file.
May contain tokens.
static fromS3Object(fileName, bucket, key, options?)
public static fromS3Object(fileName: string, bucket: IBucket, key: string, options?: InitFileOptions): InitFile
Parameters
- fileName
string
- bucket
IBucket
- key
string
- options
Init
File Options
Returns
Download a file from an S3 bucket at instance startup time.
static fromString(fileName, content, options?)
public static fromString(fileName: string, content: string, options?: InitFileOptions): InitFile
Parameters
- fileName
string
- content
string
- options
Init
File Options
Returns
Use a literal string as the file content.
static fromUrl(fileName, url, options?)
public static fromUrl(fileName: string, url: string, options?: InitFileOptions): InitFile
Parameters
- fileName
string
- url
string
- options
Init
File Options
Returns
Download from a URL at instance startup time.
static symlink(fileName, target, options?)
public static symlink(fileName: string, target: string, options?: InitFileOptions): InitFile
Parameters
- fileName
string
- target
string
- options
Init
File Options
Returns
Write a symlink with the given symlink target.