📝AWS EC2

The module that provides the AWS EC2 service.

Imports

import { AwsEc2Service } from 'niro-health';

Method of Use

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

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 {}

Injecting the module into our service.

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

IConfigurationService

IValidatorRegexpService

IStringExService

IAwsConfigurationService

IAwsStsService

Methods

Method
Scope
Description

client

public

Get the AWS EC2 client.

setRole3rdParty

public

Set the role 3rd party.

createKeyPair

public

Create a key pair.

describeKeyPair

public

Describe a key pair.

deleteKeyPair

public

Delete a key pair.

createInstance

public

Create an instance.

describeInstance

public

Describe an instance.

terminateInstance

public

Terminate an instance.

Last updated