Skip to main content

generateResourceName(params): string

Defined in: src/utils/generate-resource-name/generate-resource-name.ts:37

Generates a standardised AWS resource name using the provided components.

The name is constructed using the format: <stage>-<service>-<resource>[-<suffix>][-<region>], and converted to lowercase. If the resulting name exceeds the maximum allowed length, an error is thrown to prevent invalid resource creation.

This function is intended to fail early during synthesis or deployment to ensure compliance with AWS naming constraints across services.

Parameters

params

ResourceNameParts

The components used to generate the resource name.

Returns

string

A lowercase, hyphenated resource name suitable for AWS usage.

Throws

If the generated name exceeds the maximum allowed length.

Examples

const name = generateResourceName({ stage: 'dev', service: 'orders', resource: 'queue', suffix: 'v2', region: 'us-east-1' });
// "dev-orders-queue-v2-us-east-1"
const name = generateResourceName({ stage: 'prod', service: 'users', resource: 'table' });
// "prod-users-table"
const name = generateResourceName({ stage: 'dev', service: 'cache', resource: 'bucket', suffix: 'temp' });
// "dev-cache-bucket-temp"