# InitSource

Extract an archive into a directory.

Extends: [InitElement](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InitElement.html) › InitSource
Obtainable from: InitSource.fromAsset, InitSource.fromExistingAsset, InitSource.fromGitHub, InitSource.fromS3Object, InitSource.fromUrl

- Source: [`aws-ec2/lib/cfn-init-elements.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/cfn-init-elements.ts#L914)

## Example

TypeScript:

```ts
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,
  })
);
```

Python:

```python
# my_bucket: s3.Bucket

handle = ec2.InitServiceRestartHandle()

ec2.CloudFormationInit.from_elements(
    ec2.InitFile.from_string("/etc/nginx/nginx.conf", "...", service_restart_handles=[handle]),
    ec2.InitSource.from_s3_object("/var/www/html", my_bucket, "html.zip", service_restart_handles=[handle]),
    ec2.InitService.enable("nginx",
        service_restart_handle=handle
    ))
```

Java:

```java
Bucket myBucket;

InitServiceRestartHandle handle = new InitServiceRestartHandle();

CloudFormationInit.fromElements(InitFile.fromString("/etc/nginx/nginx.conf", "...", InitFileOptions.builder().serviceRestartHandles(List.of(handle)).build()), InitSource.fromS3Object("/var/www/html", myBucket, "html.zip", InitSourceOptions.builder().serviceRestartHandles(List.of(handle)).build()), InitService.enable("nginx", InitServiceOptions.builder()
        .serviceRestartHandle(handle)
        .build()));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Bucket myBucket;

var handle = new InitServiceRestartHandle();

CloudFormationInit.FromElements(InitFile.FromString("/etc/nginx/nginx.conf", "...", new InitFileOptions { ServiceRestartHandles = new [] { handle } }), InitSource.FromS3Object("/var/www/html", myBucket, "html.zip", new InitSourceOptions { ServiceRestartHandles = new [] { handle } }), InitService.Enable("nginx", new InitServiceOptions {
    ServiceRestartHandle = handle
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myBucket Bucket

handle := ec2.NewInitServiceRestartHandle()

ec2.CloudFormationInit_FromElements(ec2.InitFile_FromString(jsii.String("/etc/nginx/nginx.conf"), jsii.String("..."), &InitFileOptions{
	ServiceRestartHandles: []InitServiceRestartHandle{
		handle,
	},
}), ec2.InitSource_FromS3Object(jsii.String("/var/www/html"), myBucket, jsii.String("html.zip"), &InitSourceOptions{
	ServiceRestartHandles: []InitServiceRestartHandle{
		handle,
	},
}), ec2.InitService_Enable(jsii.String("nginx"), &InitServiceOptions{
	ServiceRestartHandle: handle,
}))
```

## Properties

- `elementType`: string — Returns the init element type for this element.

## Methods

- `fromAsset(targetDirectory: string, path: string, options?: InitSourceAssetOptions): InitSource // chainable` (static) — Create an InitSource from an asset created from the given path.

- `fromExistingAsset(targetDirectory: string, asset: Asset, options?: InitSourceOptions): InitSource // chainable` (static) — Extract a directory from an existing directory asset.

- `fromGitHub(targetDirectory: string, owner: string, repo: string, refSpec?: string, options?: InitSourceOptions): InitSource // chainable` (static) — Extract a GitHub branch into a given directory.

- `fromS3Object(targetDirectory: string, bucket: IBucket, key: string, options?: InitSourceOptions): InitSource // chainable` (static) — Extract an archive stored in an S3 bucket into the given directory.

- `fromUrl(targetDirectory: string, url: string, options?: InitSourceOptions): InitSource // chainable` (static) — Retrieve a URL and extract it into the given directory.
