Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(private readonly props: SagemakerTrainTaskProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.SYNC
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call SageMaker.`);
}
// set the default resource config if not defined.
this.resourceConfig = props.resourceConfig || {
instanceCount: 1,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.XLARGE),
volumeSizeInGB: 10
};
// set the stopping condition if not defined
this.stoppingCondition = props.stoppingCondition || {
constructor(private readonly lambdaFunction: lambda.IFunction, private readonly props: RunLambdaTaskProps = {}) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call Lambda.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
&& !sfn.FieldUtils.containsTaskToken(props.payload)) {
throw new Error('Task Token is missing in payload (pass Context.taskToken somewhere in payload)');
}
}
constructor(private readonly lambdaFunction: lambda.IFunction, private readonly props: RunLambdaTaskProps = {}) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call Lambda.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
&& !sfn.FieldUtils.containsTaskToken(props.payload)) {
throw new Error('Task Token is missing in payload (pass Context.taskToken somewhere in payload)');
}
}
import * as sfn from '@aws-cdk/aws-stepfunctions';
import { Aws } from '@aws-cdk/core';
/**
* Suffixes corresponding to different service integration patterns
*
* Key is the service integration pattern, value is the resource ARN suffix.
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html
*/
const resourceArnSuffix = new Map();
resourceArnSuffix.set(sfn.ServiceIntegrationPattern.FIRE_AND_FORGET, "");
resourceArnSuffix.set(sfn.ServiceIntegrationPattern.SYNC, ".sync");
resourceArnSuffix.set(sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN, ".waitForTaskToken");
export function getResourceArn(service: string, api: string, integrationPattern: sfn.ServiceIntegrationPattern): string {
if (!service || !api) {
throw new Error("Both 'service' and 'api' must be provided to build the resource ARN.");
}
return `arn:${Aws.PARTITION}:states:::${service}:${api}` +
(integrationPattern ? resourceArnSuffix.get(integrationPattern) : "");
}
constructor(private readonly queue: sqs.IQueue, private readonly props: SendToQueueProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call SQS.`);
}
if (props.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN) {
if (!sfn.FieldUtils.containsTaskToken(props.messageBody)) {
throw new Error('Task Token is missing in messageBody (pass Context.taskToken somewhere in messageBody)');
}
}
}
constructor(private readonly props: EcsRunTaskBaseProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
sfn.ServiceIntegrationPattern.SYNC
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call ECS.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
&& !sfn.FieldUtils.containsTaskToken(props.containerOverrides)) {
throw new Error('Task Token is missing in containerOverrides (pass Context.taskToken somewhere in containerOverrides)');
}
constructor(private readonly topic: sns.ITopic, private readonly props: PublishToTopicProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call SNS.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN) {
if (!sfn.FieldUtils.containsTaskToken(props.message)) {
throw new Error('Task Token is missing in message (pass Context.taskToken somewhere in message)');
}
}
}
constructor(private readonly topic: sns.ITopic, private readonly props: PublishToTopicProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call SNS.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN) {
if (!sfn.FieldUtils.containsTaskToken(props.message)) {
throw new Error('Task Token is missing in message (pass Context.taskToken somewhere in message)');
}
}
}
constructor(private readonly props: EcsRunTaskBaseProps) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
sfn.ServiceIntegrationPattern.SYNC
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call ECS.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
&& !sfn.FieldUtils.containsTaskToken(props.containerOverrides)) {
throw new Error('Task Token is missing in containerOverrides (pass Context.taskToken somewhere in containerOverrides)');
}
for (const override of this.props.containerOverrides || []) {
const name = override.containerName;
if (!cdk.Token.isUnresolved(name)) {
const cont = this.props.taskDefinition.node.tryFindChild(name);
if (!cont) {
throw new Error(`Overrides mention container with name '${name}', but no such container in task definition`);
}
}
}
}
constructor(private readonly stateMachine: sfn.IStateMachine, private readonly props: StartExecutionProps = {}) {
this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;
const supportedPatterns = [
sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
sfn.ServiceIntegrationPattern.SYNC,
sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
];
if (!supportedPatterns.includes(this.integrationPattern)) {
throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call Step Functions.`);
}
if (this.integrationPattern === sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN
&& !sfn.FieldUtils.containsTaskToken(props.input)) {
throw new Error('Task Token is missing in input (pass Context.taskToken somewhere in input)');
}
}