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(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
InitFile(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
InitFile(String, IInitFileOptions) |
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(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected InitFile(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
InitFile(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected InitFile(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
InitFile(String, IInitFileOptions)
protected InitFile(string fileName, IInitFileOptions options)
Parameters
- fileName System.String
- options IInitFileOptions
Properties
ElementType
Returns the init element type for this element.
public override string ElementType { get; }
Property Value
System.String
Overrides
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 System.String
- path System.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 System.String
- asset Asset
- options IInitFileOptions
Returns
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 System.String
- sourceFileName System.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 System.String
- obj System.Collections.Generic.IDictionary<System.String, System.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 System.String
- bucket IBucket
- key System.String
- options IInitFileOptions
Returns
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 System.String
- content System.String
- options IInitFileOptions
Returns
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 System.String
- url System.String
- options IInitFileOptions
Returns
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 System.String
- target System.String
- options IInitFileOptions
Returns