UNPKG

@allma/core-sdk

Version:

Core SDK with shared utilities (logging, auth, S3 utils) for building on the Allma serverless AI orchestration platform.

62 lines 2.48 kB
import * as cdk from 'aws-cdk-lib'; import * as iam from 'aws-cdk-lib/aws-iam'; import { AwsCustomResource, PhysicalResourceId } from 'aws-cdk-lib/custom-resources'; import { RetentionDays } from 'aws-cdk-lib/aws-logs'; /** A reusable CDK utility to register an external step in the Allma DynamoDB registry. Creates an AwsCustomResource that handles putting the item on deploy/update and deleting it on destroy. @param scope The CDK Construct scope. @param id The unique ID for this construct. @param props The properties for the step registration. */ export function createExternalStepRegistration(scope, id, props) { const { configTableName, moduleIdentifier, displayName, description, stepType, lambdaArn, defaultConfig } = props; const registrationId = `EXTERNAL_STEP#${moduleIdentifier}`; const stack = cdk.Stack.of(scope); const sdkCall = { service: 'DynamoDB', action: 'putItem', parameters: { TableName: configTableName, Item: { PK: { S: registrationId }, SK: { S: 'METADATA' }, itemType: { S: 'ALLMA_EXTERNAL_STEP_REGISTRY' }, moduleIdentifier: { S: moduleIdentifier }, lambdaArn: { S: lambdaArn }, displayName: { S: displayName }, description: { S: description }, stepType: { S: stepType }, defaultConfig: { S: JSON.stringify({ moduleIdentifier, ...defaultConfig }) }, }, }, physicalResourceId: PhysicalResourceId.of(registrationId), }; const deleteCall = { service: 'DynamoDB', action: 'deleteItem', parameters: { TableName: configTableName, Key: { PK: { S: registrationId }, SK: { S: 'METADATA' }, }, }, }; new AwsCustomResource(scope, id, { onCreate: sdkCall, onUpdate: sdkCall, onDelete: deleteCall, logRetention: RetentionDays.ONE_WEEK, installLatestAwsSdk: true, // Ensures SDK is up-to-date for DynamoDB calls policy: { statements: [ new iam.PolicyStatement({ actions: ['dynamodb:PutItem', 'dynamodb:DeleteItem'], resources: [`arn:aws:dynamodb:${stack.region}:${stack.account}:table/${configTableName}`], }), ], }, }); } //# sourceMappingURL=cdk-utils.js.map