Class InitFile
Create files on the EC2 instance.
Namespace: Amazon.CDK.AWS.EC2
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class InitFile : InitElement
Syntax (vb)
Public MustInherit Class InitFile Inherits InitElement
Remarks
ExampleMetadata: infused
Examples
Vpc vpc;
InstanceType instanceType;
new Instance(this, "Instance", new InstanceProps {
Vpc = vpc,
InstanceType = instanceType,
MachineImage = MachineImage.LatestAmazonLinux2023(),
Init = CloudFormationInit.FromElements(InitService.SystemdConfigFile("simpleserver", new SystemdConfigFileOptions {
Command = "/usr/bin/python3 -m http.server 8080",
Cwd = "/var/www/html"
}), InitService.Enable("simpleserver", new InitServiceOptions {
ServiceManager = ServiceManager.SYSTEMD
}), InitFile.FromString("/var/www/html/index.html", "Hello! It's working!"))
});
Synopsis
Constructors
| InitFile(string, IInitFileOptions) | Create files on the EC2 instance. |
Properties
| ElementType | Returns the init element type for this element. |
Methods
| FromAsset(string, string, IInitFileAssetOptions?) | Create an asset from the given file. |
| FromExistingAsset(string, Asset, IInitFileOptions?) | Use a file from an asset at instance startup time. |
| FromFileInline(string, string, IInitFileOptions?) | Read a file from disk and use its contents. |
| FromObject(string, IDictionary<string, object>, IInitFileOptions?) | Use a JSON-compatible object as the file content, write it to a JSON file. |
| FromS3Object(string, IBucket, string, IInitFileOptions?) | Download a file from an S3 bucket at instance startup time. |
| FromString(string, string, IInitFileOptions?) | Use a literal string as the file content. |
| FromUrl(string, string, IInitFileOptions?) | Download from a URL at instance startup time. |
| Symlink(string, string, IInitFileOptions?) | Write a symlink with the given symlink target. |
Constructors
InitFile(string, IInitFileOptions)
Create files on the EC2 instance.
protected InitFile(string fileName, IInitFileOptions options)
Parameters
- fileName string
- options IInitFileOptions
Remarks
ExampleMetadata: infused
Examples
Vpc vpc;
InstanceType instanceType;
new Instance(this, "Instance", new InstanceProps {
Vpc = vpc,
InstanceType = instanceType,
MachineImage = MachineImage.LatestAmazonLinux2023(),
Init = CloudFormationInit.FromElements(InitService.SystemdConfigFile("simpleserver", new SystemdConfigFileOptions {
Command = "/usr/bin/python3 -m http.server 8080",
Cwd = "/var/www/html"
}), InitService.Enable("simpleserver", new InitServiceOptions {
ServiceManager = ServiceManager.SYSTEMD
}), InitFile.FromString("/var/www/html/index.html", "Hello! It's working!"))
});
Properties
ElementType
Returns the init element type for this element.
public override string ElementType { get; }
Property Value
Overrides
Remarks
ExampleMetadata: infused
Methods
FromAsset(string, string, IInitFileAssetOptions?)
Create an asset from the given file.
public static InitFile FromAsset(string targetFileName, string path, IInitFileAssetOptions? options = null)
Parameters
- targetFileName string
- path string
- options IInitFileAssetOptions
Returns
Remarks
This is appropriate for files that are too large to embed into the template.
FromExistingAsset(string, Asset, IInitFileOptions?)
Use a file from an asset at instance startup time.
public static InitFile FromExistingAsset(string targetFileName, Asset asset, IInitFileOptions? options = null)
Parameters
- targetFileName string
- asset Asset
- options IInitFileOptions
Returns
Remarks
ExampleMetadata: infused
FromFileInline(string, string, IInitFileOptions?)
Read a file from disk and use its contents.
public static InitFile FromFileInline(string targetFileName, string sourceFileName, IInitFileOptions? options = null)
Parameters
- targetFileName string
- sourceFileName string
- options IInitFileOptions
Returns
Remarks
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.
FromObject(string, IDictionary<string, object>, IInitFileOptions?)
Use a JSON-compatible object as the file content, write it to a JSON file.
public static InitFile FromObject(string fileName, IDictionary<string, object> obj, IInitFileOptions? options = null)
Parameters
- fileName string
- obj IDictionary<string, object>
- options IInitFileOptions
Returns
Remarks
May contain tokens.
FromS3Object(string, IBucket, string, IInitFileOptions?)
Download a file from an S3 bucket at instance startup time.
public static InitFile FromS3Object(string fileName, IBucket bucket, string key, IInitFileOptions? options = null)
Parameters
- fileName string
- bucket IBucket
- key string
- options IInitFileOptions
Returns
Remarks
ExampleMetadata: infused
FromString(string, string, IInitFileOptions?)
Use a literal string as the file content.
public static InitFile FromString(string fileName, string content, IInitFileOptions? options = null)
Parameters
- fileName string
- content string
- options IInitFileOptions
Returns
Remarks
ExampleMetadata: infused
FromUrl(string, string, IInitFileOptions?)
Download from a URL at instance startup time.
public static InitFile FromUrl(string fileName, string url, IInitFileOptions? options = null)
Parameters
- fileName string
- url string
- options IInitFileOptions
Returns
Remarks
ExampleMetadata: infused
Symlink(string, string, IInitFileOptions?)
Write a symlink with the given symlink target.
public static InitFile Symlink(string fileName, string target, IInitFileOptions? options = null)
Parameters
- fileName string
- target string
- options IInitFileOptions
Returns
Remarks
ExampleMetadata: infused