@vyriy/services
v0.8.9
Published
Shared services package for Vyriy projects
Readme
@vyriy/services
Part of Vyriy - a calm architecture toolkit for TypeScript, React, SSR, SSG, APIs, and cloud-ready apps.
Full documentation: https://vyriy.dev/docs/services/
Small AWS service SDK for Vyriy projects.
Purpose
This package wraps common AWS SDK operations behind calm, reusable helpers. It is not meant to hide AWS. It keeps the AWS command inputs available where they are useful, while removing repeated client setup and common boilerplate from app, script, service, and deployment code.
The package is AWS-first and serverless-oriented. Current helpers cover:
cloudfront: create invalidations and optionally wait for completiondynamodb: create tables and read/write/query/scan document itemsecs: start one Fargate task with environment overrideslambda: invoke Lambda functions with JSON string payloadslogs: wait for marker strings in CloudWatch Logss3: upload, download, and check object existencesns: publish messages to topicsssm: read one or many Parameter Store values
Install
With npm:
npm install @vyriy/servicesWith Yarn:
yarn add @vyriy/servicesLocalStack
Some clients are prepared for local AWS-compatible development:
dynamodbusesLOCALSTACK_HOSTandLOCALSTACK_PORTas its endpoint when@vyriy/envreports the local stage.s3uses the same LocalStack endpoint in local stage and enablesforcePathStyle.ecsuses the configured region in local stage, but does not point to a LocalStack endpoint.cloudfront,lambda,logs,sns, andssmcurrently use their normal AWS SDK client configuration.
Service clients are created lazily inside each helper call. Importing
@vyriy/services or a service subpath does not construct AWS SDK clients.
LocalStack defaults come from @vyriy/env:
LOCALSTACK_HOST: defaults tolocalhostLOCALSTACK_PORT: defaults to4566
Usage
Import from the package root:
import * as services from '@vyriy/services';
await services.s3.upload('assets-bucket', 'pages/index.html', '<html>...</html>', 'text/html');
await services.lambda.invoke('my-function', JSON.stringify({ ok: true }));Or import a service subpath directly:
import { getParameter } from '@vyriy/services/ssm';
import { upload } from '@vyriy/services/s3';
const apiUrl = await getParameter('/app/api-url');
await upload('assets-bucket', 'config/api-url.txt', apiUrl, 'text/plain');Wait for a Lambda log marker and clean up the source S3 object:
import { logs, s3 } from '@vyriy/services';
await s3.upload('email-bucket', 'messages/test.eml', rawEmail, 'message/rfc822; charset=utf-8');
try {
await logs.waitForMarker('/aws/lambda/process-email', marker);
} finally {
await s3.remove('email-bucket', 'messages/test.eml');
}Client factories are also exported from service subpaths when direct AWS SDK
access is needed. The service path gives the generic createClient name its
context:
import { createClient } from '@vyriy/services/s3';
const client = createClient({ region: 'eu-central-1' });Examples
Invalidate CloudFront after publishing static files:
import { invalidate } from '@vyriy/services/cloudfront';
await invalidate('DISTRIBUTION_ID', ['/index.html', '/assets/*'], true);Run a Fargate task:
import { runTask } from '@vyriy/services/ecs';
await runTask('regenerate-pages', [{ name: 'CONTENT_ID', value: 'home' }]);Read application settings from SSM:
import { getParameters } from '@vyriy/services/ssm';
const settings = await getParameters(['/app/api-url', '/app/cdn-url']);