AWS-Tools
A collection of utilities for interacting with AWS Services.
Installation
pnpm i @pit-shared/aws-tools
Services
Simple Systems Manager
allows interacting with AWS-SSM
Usage
import {
getParameterByName,
getParametersByPath,
writeParameter,
} from '@pit-shared/aws-tools/ssm'
// write parameter
await writeParameter('/path/to/parameters/a', 'lolcathost', 'aws-region')
// get single parameter
const parameter = await getParameterByName(
'/path/to/parameters/a',
'aws-region',
)
// get all parameters beneath a path
const parameters = await getParametersByPath(
'/path/to/parameters',
'aws-region',
)
Secrets Manager
allows interacting with AWS-Secrets-Manager
Usage
import { getSecret } from '@pit-shared/aws-tools/secrets-manager'
// getSecret Value
const secretValue = await getSecret('secretName', 'aws-region')
Cloudformation
allows interacting AWS-Cloudformation
Usage
import { getStackOutput } from '@pit-shared/aws-tools/cloudformation'
// get the whole stack output as Output[]
const output = await getStackOutput('stackName', 'aws-region')
// get a specific output variable from a stack
const variable = await getStackOutputVariableVariable(
'stackName',
'outputVariable',
'aws-region',
)
Security Token Service
allows interacting AWS-STS
Usage
import { getAccountId, getUserId } from '@pit-shared/aws-tools/sts'
// get the current AWS-AccountId
const accountId = await getAccountId()
// get the current AWS-UserId
const userId = await getUserId()
Environment
checks and prepare the env variables for use with AWS Services
Usage
import { ensureCredentials, getRegion } from '@pit-shared/aws-tools/env'
// check if the environment is prepared for interacting with AWS
await ensureCredentials()
// get the current AWS-Region (if set)
const region = await getRegion()
Elastic Container Service
allows interacting with ECS
Usage
import {
describeClusters,
listClusters,
listServices,
updateService,
waitForServicesDeployment,
} from '@pit-shared/aws-tools/ecs'
const clusterArns = await listClusters('aws-region')
const clusterDetails = await describeClusters(clusterArns, 'aws-region')
const serviceArns = await listServices(clusterArns[0], 'aws-region')
const service = await updateService(
clusterArns[0],
serviceArns[0],
'aws-region',
)
const deployment = await waitForServicesDeployment(
clusterArns[0],
serviceArns,
'aws-region',
)
Elastic Container Registry
allows interacting with ECR
Usage
import { getAuthorization } from '@pit-shared/aws-tools/ecr'
const authData = await getAuthorization('aws-region')
Cloudfront
allows to interact with Cloudfront
Usage
import { getDistributionIdForDomain, getInvalidationStatus, invalidateDistribution, testCloudfrontFunction } from '@pit-shared/aws-tools/cloudfront'
// see https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/add-cache-control-header/test-event.json for an example event
const result = await testCloudfrontFunction(
'functionName',
'json payload as string',
)
// invalidation
const distributionId = await getDistributionIdForDomain('https://statista.com')
const invalidationId = await invalidateDistribution(distributionId, ['/*'])
const invalidationStatus = await getInvalidationStatus(distributionId, invalidationId)
Resource Manager
allows to interact with Resource-Explorer
Usage
import { getAllUsedServices } from '@pit-shared/aws-tools/resource-manager'
const result = await getAllUsedServices('aws-region')