> For the complete documentation index, see [llms.txt](https://guilhermesantos.gitbook.io/niro-health/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guilhermesantos.gitbook.io/niro-health/modules/aws-ec2.md).

# AWS EC2

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { AwsEc2Service } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { AwsEc2Module } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IAwsEc2Service } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Method of Use

To use this module, you need to inject it into the desired service.

{% code overflow="wrap" %}

```typescript
import { Module } from '@nestjs/common';
import {
  AwsEc2Service,
  AwsCoreService,
  AwsConfigurationService,
  AwsStsService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IAwsEc2Service',
      useClass: AwsEc2Service,
    },
    {
      provide: 'IAwsCoreService',
      useClass: AwsCoreService,
    },
    {
      provide: 'IAwsConfigurationService',
      useClass: AwsConfigurationService,
    },
    {
      provide: 'IAwsStsService',
      useClass: AwsStsService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
  ],
})
export class AppModule {}
```

{% endcode %}

Injecting the module into our service.

```typescript
import { Inject, Injectable } from '@nestjs/common';
import type { IAwsEc2Service } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IAwsEc2Service')
    private readonly awsEc2Service: IAwsEc2Service,
  ) {}

  async createInstance() {
    return await this.awsEc2Service.createInstance(
      'ami-0a58e22c727337c51',
      't2.micro',
      'sg-0a1b2c3d4e5f6g7h8',
    );
  }
}
```

### With dependencies

You will need to inject the following interfaces.

| Interface                  | Service                                                                    |
| -------------------------- | -------------------------------------------------------------------------- |
| `IAwsCoreService`          | [Link to Service documentation](/niro-health/modules/aws-core.md)          |
| `IConfigurationService`    | [Link to Service documentation](/niro-health/modules/configuration.md)     |
| `IValidatorRegexpService`  | [Link to Service documentation](/niro-health/modules/validator-regexp.md)  |
| `IStringExService`         | [Link to Service documentation](/niro-health/modules/stringex.md)          |
| `IAwsConfigurationService` | [Link to Service documentation](/niro-health/modules/aws-configuration.md) |
| `IAwsStsService`           | [Link to Service documentation](/niro-health/modules/aws-sts.md)           |

### Methods

<table><thead><tr><th>Method</th><th width="106.33333333333331" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>client</code></td><td align="center"><code>public</code></td><td><code>Get the AWS EC2 client.</code></td></tr><tr><td><code>setRole3rdParty</code></td><td align="center"><code>public</code></td><td><code>Set the role 3rd party.</code></td></tr><tr><td><code>createKeyPair</code></td><td align="center"><code>public</code></td><td><code>Create a key pair.</code></td></tr><tr><td><code>describeKeyPair</code></td><td align="center"><code>public</code></td><td><code>Describe a key pair.</code></td></tr><tr><td><code>deleteKeyPair</code></td><td align="center"><code>public</code></td><td><code>Delete a key pair.</code></td></tr><tr><td><code>createInstance</code></td><td align="center"><code>public</code></td><td><code>Create an instance.</code></td></tr><tr><td><code>describeInstance</code></td><td align="center"><code>public</code></td><td><code>Describe an instance.</code></td></tr><tr><td><code>terminateInstance</code></td><td align="center"><code>public</code></td><td><code>Terminate an instance.</code></td></tr></tbody></table>
