Skip to content

generateFromAwsResponse

function generateFromAwsResponse(params): SvgOutput;

Defined in: src/index.ts:323

Generate a diagram from an AWS SDK DescribeStateMachine response

This is a convenience function for integrating with the AWS SDK. It extracts the ASL definition from the response and generates a diagram.

Pass format as a literal ('svg' or 'mermaid') to get the matching output type; omitted or non-literal, the return type is the union (SVG at runtime when omitted). For HTML, pass response.definition to generateHtml from sfn-diagram/html.

GenerateFromAwsParams & object

Configuration object

SvgOutput

SVG output if format is ‘svg’, Mermaid output if format is ‘mermaid’

If response.definition is missing, or if format is ‘html’ or ‘png’

If the definition contains invalid JSON (also an instanceof SyntaxError and AslValidationError)

If the ASL definition structure is invalid

import { SFNClient, DescribeStateMachineCommand } from '@aws-sdk/client-sfn';
import { generateFromAwsResponse } from 'sfn-diagram';
const client = new SFNClient({ region: 'us-east-1' });
const response = await client.send(
new DescribeStateMachineCommand({
stateMachineArn: 'arn:aws:states:...'
})
);
const { svg } = generateFromAwsResponse({
response,
format: 'svg',
theme: 'light',
layout: 'TB'
});
function generateFromAwsResponse(params): MermaidOutput;

Defined in: src/index.ts:335

Generate a Mermaid diagram from an AWS SDK DescribeStateMachine response.

GenerateFromAwsParams & object

Configuration object with format: 'mermaid'

MermaidOutput

Mermaid output

If response.definition is missing, or the ASL definition is invalid

const { code } = generateFromAwsResponse({ response, format: 'mermaid' });
function generateFromAwsResponse(params):
| SvgOutput
| MermaidOutput;

Defined in: src/index.ts:349

Generate a diagram from an AWS SDK response whose format is omitted or not known at compile time.

GenerateFromAwsParams

Configuration object

| SvgOutput | MermaidOutput

The union; SVG at runtime when format is omitted

If response.definition is missing, the ASL definition is invalid, or format is ‘html’ or ‘png’

const result = generateFromAwsResponse({ response });
if ('svg' in result) { console.log(result.svg); }