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. |
Asset(targetFileName, path, options?)
static frompublic 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.
ExistingAsset(targetFileName, asset, options?)
static frompublic 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.
FileInline(targetFileName, sourceFileName, options?)
static frompublic 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.
Object(fileName, obj, options?)
static frompublic 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.
S3Object(fileName, bucket, key, options?)
static frompublic 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.
String(fileName, content, options?)
static frompublic 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.
Url(fileName, url, options?)
static frompublic 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.