cloudydeno / deno-aws_api

From-scratch Typescript client for accessing AWS APIs
https://deno.land/x/aws_api
59 stars 3 forks source link
aws aws-sdk deno deno-apis typescript typescript-library

aws_api for Deno

CI Status Latest /x/ version external dependency count dependency outdatedness

From-scratch Typescript AWS API client built for Deno.

This library's goal is to codegen type-safe AWS service clients while importing a relatively small number of dependency modules.

Each AWS service has its own module that you can import from several URLs. To use, you can create a new ApiFactory() (which manages credentials and such), and then use it to construct a client for the AWS service API you want to use.

Example Usage

A bare-bones example from demo.ts:

import { ApiFactory } from 'https://deno.land/x/aws_api/client/mod.ts';
import { STS } from 'https://deno.land/x/aws_api/services/sts/mod.ts';

// Create a service client for AWS Security Token Service
const sts = new ApiFactory().makeNew(STS);

// Call the STS "GetCallerIdentity" API
const identity = await sts.getCallerIdentity();
console.log('You are', identity.UserId, 'in account', identity.Account);
console.log('Identity ARN:', identity.Arn);

Several larger examples in examples/ show concepts such as launching & managing an EC2 instance, redriving SQS messages from a dead-letter queue, and writing & reading records within a Kinesis stream.

Who Should Use This Library?

This aws_api Deno module is good for:

This module alone is not good for:

Disclaimer

This is NOT a port of the official AWS SDK JS. Though this project can generate a client for every AWS service, I have only personally tested it with a couple dozen services and the bindings might make incorrect assumptions about individual API contracts.

Do not use this module in mission critical stuff. It's intended for automation scripts, quick & dirty pieces of infrastructure, prototype microservices and so on.

If you just want the real, full-fat AWS SDK, check out this aws-sdk-js-v3 issue. A port of the AWS SDK has also been uploaded at /x/aws_sdk.

The exported logic within client/ and encoding/ are liable to change from refactor. For best upgradability, stick to constructing an ApiFactory object and passing it to the services.

Importing Service Clients

The services/ folder contains complete API clients for several key services. These include S3, DynamoDB, Lambda, S3, and SQS/SNS. There's also CloudWatch, ECR, Kinesis, KMS, Route53, SES, and STS.

For other services, or to cut down on dependency size by selecting the available actions, you can import from the /x/aws_api Web Service:

import { ApiFactory } from 'https://deno.land/x/aws_api/client/mod.ts';
import { Pricing } from 'https://aws-api.deno.dev/latest/services/pricing.ts';

const pricing = new ApiFactory().makeNew(Pricing);
const { Services } = await pricing.describeServices('AmazonEC2');
console.log('Found', Services.length, 'services:');
for (const serviceItem of Services) {
  console.log('  -', serviceItem.ServiceCode);
}

More information can be found on the accompanying Wiki page.

Client Configuration

The ApiFactory constructor accepts optional configuration as an options object. If you need to change something, pass one of these properties:

For example, to access the EC2 API of a particular region:

const ec2_europe = new ApiFactory({
  region: 'eu-west-1',
}).makeNew(EC2);

Changelog

About this library

Package layout

Please reach out on Github Issues about missing features, weird exceptions, or API issues, or ping dantheman#8546 in the Deno Discord if you just wanna chat about this effort.

Methodology

All of the clients are compiled from aws-sdk-js's JSON data files. The code to generate clients isn't uploaded to /x/, so if you want to read through it, make sure you're in the source Git repo.

"Most" of the heavy lifting (such as compiling waiter JMESPaths) runs in the generation step so that the downloaded code is ready to run.

Completeness

The following clients have been used in actual scripts and should work quite well:

The following credential sources are supported:

Some individual features that are implemented:

Multiple bits are missing:

List of Pre-Generated API Clients

All API definitions are current as of aws-sdk-js v2.1060.0.

Class Module Protocol
CloudWatch cloudwatch/mod.ts query
DynamoDB dynamodb/mod.ts json
ECR ecr/mod.ts json
Kinesis kinesis/mod.ts json
KMS kms/mod.ts json
Lambda lambda/mod.ts rest-json
Route53 route53/mod.ts rest-xml
S3 s3/mod.ts rest-xml
SESV2 sesv2/mod.ts rest-json
SNS sns/mod.ts query
SQS sqs/mod.ts query
STS sts/mod.ts query

For any other services, please check out the code generation web service which performs on-the-fly code generation. You can import the generated URL directly in your application, or download a copy of the file and save it in your source code for safe keeping.

The last version of this library to include every then-current API client on /x/ is v0.3.1.

Breaking Changes Archive

v0.4.0

  1. Version 0.4.0 of this library stopped including every service's API in the published module. Instead, the code-generation process is running on Deno Deploy and allows importing extremely precise modules, generated on the fly based on multiple configuration options.

    Check out this Web Service wiki page for more details on this new URL endpoint. Please report any issues or concerns with this new approach.

  2. For services that are still bundled (SQS, S3, SNS, etc), the import URL no longer includes an API version (the @year-month-date part). Only the most recent API version gets bundled.

  3. The primary class export on each service module is no longer 'default'. So instead of import SQS from ..., you'll do import { SQS } from .....