yandex-cloud / nodejs-sdk

Yandex.Cloud NodeJS SDK
MIT License
64 stars 13 forks source link
cloud nodejs sdk yandex-cloud

Yandex.Cloud SDK (nodejs)

npm License

Need to automate your infrastructure or use services provided by Yandex.Cloud? We've got you covered.

Requirements

Installation

npm install @yandex-cloud/nodejs-sdk

Getting started

There are three options for authorization your requests:

OAuth Token

import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk';

const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;

// Initialize SDK with your token
const session = new Session({ oauthToken: 'YOUR_TOKEN' });

// Create service client
const cloudService = session.client(serviceClients.CloudServiceClient);

// Issue request (returns Promise)
const response = await cloudService.list(ListCloudsRequest.fromPartial({
    pageSize: 100,
}));

Metadata Service

Don't forget to assign Service Account for your Instance or Function.

import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk';

const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;

// Initialize SDK with your token
const session = new Session();

// Create service client
const cloudService = session.client(serviceClients.CloudServiceClient);

// Issue request (returns Promise)
const response = await cloudService.list(ListCloudsRequest.fromPartial({
    pageSize: 100,
}));

IAM Token

import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk';

const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;

// Initialize SDK with your token
const session = new Session({ iamToken: 'YOUR_TOKEN' });

// Create service client
const cloudService = session.client(serviceClients.CloudServiceClient);

// Issue request (returns Promise)
const response = await cloudService.list(ListCloudsRequest.fromPartial({
    pageSize: 100,
}));

Check examples directory for more examples.

To run example scripts, you should execute the following commands:

cd examples
npm i
YC_OAUTH_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts

Services

If you need generated client for other Yandex.Cloud services, just open an issue.