UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 16.6 kB
"use strict";var __runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChainDefinitionBody=exports.StringDefinitionBody=exports.FileDefinitionBody=exports.DefinitionBody=exports.StateMachine=exports.LogLevel=exports.StateMachineType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var customer_managed_key_encryption_configuration_1=()=>{var tmp=require("./customer-managed-key-encryption-configuration");return customer_managed_key_encryption_configuration_1=()=>tmp,tmp},util_1=()=>{var tmp=require("./private/util");return util_1=()=>tmp,tmp},state_graph_1=()=>{var tmp=require("./state-graph");return state_graph_1=()=>tmp,tmp},state_machine_grants_1=()=>{var tmp=require("./state-machine-grants");return state_machine_grants_1=()=>tmp,tmp},stepfunctions_canned_metrics_generated_1=()=>{var tmp=require("./stepfunctions-canned-metrics.generated");return stepfunctions_canned_metrics_generated_1=()=>tmp,tmp},stepfunctions_generated_1=()=>{var tmp=require("./stepfunctions.generated");return stepfunctions_generated_1=()=>tmp,tmp},cloudwatch=()=>{var tmp=require("../../aws-cloudwatch");return cloudwatch=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},s3_assets=()=>{var tmp=require("../../aws-s3-assets");return s3_assets=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},StateMachineType;(function(StateMachineType2){StateMachineType2.EXPRESS="EXPRESS",StateMachineType2.STANDARD="STANDARD"})(StateMachineType||(exports.StateMachineType=StateMachineType={}));var LogLevel;(function(LogLevel2){LogLevel2.OFF="OFF",LogLevel2.ALL="ALL",LogLevel2.ERROR="ERROR",LogLevel2.FATAL="FATAL"})(LogLevel||(exports.LogLevel=LogLevel={}));class StateMachineBase extends core_1().Resource{static fromStateMachineArn(scope,id,stateMachineArn){class Import extends StateMachineBase{stateMachineArn=stateMachineArn;grantPrincipal=new(iam()).UnknownPrincipal({resource:this})}return new Import(scope,id,{environmentFromArn:stateMachineArn})}static fromStateMachineName(scope,id,stateMachineName){const stateMachineArn=core_1().Stack.of(scope).formatArn({service:"states",resource:"stateMachine",arnFormat:core_1().ArnFormat.COLON_RESOURCE_NAME,resourceName:stateMachineName});return this.fromStateMachineArn(scope,id,stateMachineArn)}grants=state_machine_grants_1().StateMachineGrants.fromStateMachine(this);get stateMachineRef(){return{stateMachineArn:this.stateMachineArn}}grantStartExecution(identity){return this.grants.startExecution(identity)}grantStartSyncExecution(identity){return this.grants.startSyncExecution(identity)}grantRead(identity){return this.grants.read(identity)}grantTaskResponse(identity){return this.grants.taskResponse(identity)}grantExecution(identity,...actions){return this.grants.execution(identity,...actions)}grantRedriveExecution(identity){return this.grantExecution(identity,"states:RedriveExecution")}grant(identity,...actions){return this.grants.actions(identity,...actions)}metric(metricName,props){return new(cloudwatch()).Metric({namespace:"AWS/States",metricName,dimensionsMap:{StateMachineArn:this.stateMachineArn},statistic:"sum",...props}).attachTo(this)}metricFailed(props){return this.cannedMetric(stepfunctions_canned_metrics_generated_1().StatesMetrics.executionsFailedSum,props)}metricThrottled(props){return this.metric("ExecutionThrottled",props)}metricAborted(props){return this.cannedMetric(stepfunctions_canned_metrics_generated_1().StatesMetrics.executionsAbortedSum,props)}metricSucceeded(props){return this.cannedMetric(stepfunctions_canned_metrics_generated_1().StatesMetrics.executionsSucceededSum,props)}metricTimedOut(props){return this.cannedMetric(stepfunctions_canned_metrics_generated_1().StatesMetrics.executionsTimedOutSum,props)}metricStarted(props){return this.metric("ExecutionsStarted",props)}metricTime(props){return this.cannedMetric(stepfunctions_canned_metrics_generated_1().StatesMetrics.executionTimeAverage,props)}cannedMetric(fn,props){return new(cloudwatch()).Metric({...fn({StateMachineArn:this.stateMachineArn}),...props}).attachTo(this)}}let StateMachine=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=StateMachineBase,_instanceExtraInitializers=[],_addToRolePolicy_decorators;var StateMachine2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_addToRolePolicy_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_addToRolePolicy_decorators,{kind:"method",name:"addToRolePolicy",static:!1,private:!1,access:{has:obj=>"addToRolePolicy"in obj,get:obj=>obj.addToRolePolicy},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),StateMachine2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.StateMachine",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-stepfunctions.StateMachine";role=__runInitializers(this,_instanceExtraInitializers);stateMachineName;stateMachineArn;stateMachineType;stateMachineRevisionId;constructor(scope,id,props){super(scope,id,{physicalName:props.stateMachineName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateMachineProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,StateMachine2),error}if((0,metadata_resource_1().addConstructMetadata)(this,props),props.definition&&props.definitionBody)throw new(core_1()).ValidationError("Cannot specify definition and definitionBody at the same time",this);if(!props.definition&&!props.definitionBody)throw new(core_1()).ValidationError("You need to specify either definition or definitionBody",this);props.stateMachineName!==void 0&&this.validateStateMachineName(props.stateMachineName),props.logs&&this.validateLogOptions(props.logs),this.role=props.role||new(iam()).Role(this,"Role",{assumedBy:new(iam()).ServicePrincipal("states.amazonaws.com")});const definitionBody=props.definitionBody??DefinitionBody.fromChainable(props.definition);this.stateMachineType=props.stateMachineType??StateMachineType.STANDARD;let graph;if(definitionBody instanceof ChainDefinitionBody){graph=new(state_graph_1()).StateGraph(definitionBody.chainable.startState,"State Machine definition"),graph.timeout=props.timeout;for(const statement of graph.policyStatements)this.addToRolePolicy(statement)}props.encryptionConfiguration instanceof customer_managed_key_encryption_configuration_1().CustomerManagedEncryptionConfiguration&&(this.role.addToPrincipalPolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,actions:["kms:Decrypt","kms:GenerateDataKey"],resources:[`${props.encryptionConfiguration.kmsKey.keyArn}`],conditions:{StringEquals:{"kms:EncryptionContext:aws:states:stateMachineArn":core_1().Stack.of(this).formatArn({service:"states",resource:"stateMachine",sep:":",resourceName:this.physicalName})}}})),props.logs&&props.logs.level!==LogLevel.OFF&&(this.role.addToPrincipalPolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,actions:["kms:GenerateDataKey"],resources:[`${props.encryptionConfiguration.kmsKey.keyArn}`],conditions:{StringEquals:{"kms:EncryptionContext:SourceArn":core_1().Stack.of(this).formatArn({service:"logs",resource:"*",sep:":"})}}})),props.encryptionConfiguration.kmsKey.addToResourcePolicy(new(iam()).PolicyStatement({resources:["*"],actions:["kms:Decrypt*"],principals:[new(iam()).ServicePrincipal("delivery.logs.amazonaws.com")]}))));const resource=new(stepfunctions_generated_1()).CfnStateMachine(this,"Resource",{stateMachineName:this.physicalName,stateMachineType:props.stateMachineType??void 0,roleArn:this.role.roleArn,loggingConfiguration:props.logs?this.buildLoggingConfiguration(props.logs):void 0,tracingConfiguration:this.buildTracingConfiguration(props.tracingEnabled),...definitionBody.bind(this,this.role,props,graph),definitionSubstitutions:props.definitionSubstitutions,encryptionConfiguration:(0,util_1().buildEncryptionConfiguration)(props.encryptionConfiguration)});resource.applyRemovalPolicy(props.removalPolicy,{default:core_1().RemovalPolicy.DESTROY}),resource.node.addDependency(this.role),this.stateMachineName=this.getResourceNameAttribute(resource.attrName),this.stateMachineArn=this.getResourceArnAttribute(resource.ref,{service:"states",resource:"stateMachine",resourceName:this.physicalName,arnFormat:core_1().ArnFormat.COLON_RESOURCE_NAME}),definitionBody instanceof ChainDefinitionBody&&graph.bind(this),this.stateMachineRevisionId=resource.attrStateMachineRevisionId}get grantPrincipal(){return this.role.grantPrincipal}addToRolePolicy(statement){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_PolicyStatement(statement)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addToRolePolicy),error}this.role.addToPrincipalPolicy(statement)}validateStateMachineName(stateMachineName){if(!core_1().Token.isUnresolved(stateMachineName)){if(stateMachineName.length<1||stateMachineName.length>80)throw new(core_1()).ValidationError(`State Machine name must be between 1 and 80 characters. Received: ${stateMachineName}`,this);if(!stateMachineName.match(/^[a-z0-9\+\!\@\.\(\)\-\=\_\']+$/i))throw new(core_1()).ValidationError(`State Machine name must match "^[a-z0-9+!@.()-=_']+$/i". Received: ${stateMachineName}`,this)}}validateLogOptions(logOptions){if(logOptions.level!==LogLevel.OFF&&!logOptions.destination)throw new(core_1()).ValidationError("Logs destination is required when level is not OFF.",this)}buildLoggingConfiguration(logOptions){let destinations;return logOptions.destination&&(this.addToRolePolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,actions:["logs:CreateLogDelivery","logs:GetLogDelivery","logs:UpdateLogDelivery","logs:DeleteLogDelivery","logs:ListLogDeliveries","logs:PutResourcePolicy","logs:DescribeResourcePolicies","logs:DescribeLogGroups"],resources:["*"]})),destinations=[{cloudWatchLogsLogGroup:{logGroupArn:logOptions.destination.logGroupArn}}]),{destinations,includeExecutionData:logOptions.includeExecutionData,level:logOptions.level||"ERROR"}}buildTracingConfiguration(isTracing){if(isTracing!==void 0)return isTracing&&this.addToRolePolicy(new(iam()).PolicyStatement({actions:["xray:PutTraceSegments","xray:PutTelemetryRecords","xray:GetSamplingRules","xray:GetSamplingTargets"],resources:["*"]})),{enabled:isTracing}}static{__runInitializers(_classThis,_classExtraInitializers)}};return StateMachine2=_classThis})();exports.StateMachine=StateMachine;class DefinitionBody{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.DefinitionBody",version:"2.233.0"};static fromFile(path,options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_assets_AssetOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromFile),error}return new FileDefinitionBody(path,options)}static fromString(definition){return new StringDefinitionBody(definition)}static fromChainable(chainable){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_IChainable(chainable)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromChainable),error}return new ChainDefinitionBody(chainable)}}exports.DefinitionBody=DefinitionBody;class FileDefinitionBody extends DefinitionBody{path;options;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.FileDefinitionBody",version:"2.233.0"};constructor(path,options={}){super(),this.path=path,this.options=options;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_s3_assets_AssetOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,FileDefinitionBody),error}}bind(scope,_sfnPrincipal,_sfnProps,_graph){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IPrincipal(_sfnPrincipal),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateMachineProps(_sfnProps),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateGraph(_graph)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const asset=new(s3_assets()).Asset(scope,"DefinitionBody",{path:this.path,...this.options});return{definitionS3Location:{bucket:asset.s3BucketName,key:asset.s3ObjectKey}}}}exports.FileDefinitionBody=FileDefinitionBody;class StringDefinitionBody extends DefinitionBody{body;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.StringDefinitionBody",version:"2.233.0"};constructor(body){super(),this.body=body}bind(_scope,_sfnPrincipal,_sfnProps,_graph){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IPrincipal(_sfnPrincipal),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateMachineProps(_sfnProps),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateGraph(_graph)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}return{definitionString:this.body}}}exports.StringDefinitionBody=StringDefinitionBody;class ChainDefinitionBody extends DefinitionBody{chainable;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.ChainDefinitionBody",version:"2.233.0"};constructor(chainable){super(),this.chainable=chainable;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_IChainable(chainable)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,ChainDefinitionBody),error}}bind(scope,_sfnPrincipal,sfnProps,graph){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IPrincipal(_sfnPrincipal),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateMachineProps(sfnProps),jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateGraph(graph)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const graphJson=graph.toGraphJson(sfnProps.queryLanguage);return{definitionString:core_1().Stack.of(scope).toJsonString({...graphJson,Comment:sfnProps.comment,QueryLanguage:sfnProps.queryLanguage})}}}exports.ChainDefinitionBody=ChainDefinitionBody;