-
Notifications
You must be signed in to change notification settings - Fork 2.3k
add stepfunctions with external asl definition file #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b3f8e2c
add stepfunctions with external asl definition file
pedramha 042ff2c
Merge branch 'main' into main
kaiz-io d6e468b
Merge branch 'main' into main
kaiz-io 6ef417f
Delete typescript/stepfunction-external-definition/test/stepfunction-…
kaiz-io 2540f51
Update package.json
kaiz-io 226e664
Delete typescript/stepfunction-external-definition/jest.config.js
kaiz-io 9bdfc32
change permission setting
pedramha 948e7f6
Merge branch 'main' into main
kaiz-io c701c87
Merge branch 'main' into main
kaiz-io File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| *.js | ||
| !jest.config.js | ||
| *.d.ts | ||
| node_modules | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| *.ts | ||
| !*.d.ts | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Welcome to your CDK TypeScript project | ||
|
|
||
| This is a Tyepscript CDK project which enables implementing stepfunctions with external asl(Amazon States Language) file. This can be useful in usecases where it is desired to leverage local development flow of the stepfunction statemachines,e.g. AWS toolkit for VScode, and directly import the asl file into your project without rewriting it in CDK. | ||
|
|
||
| The `cdk.json` file tells the CDK Toolkit how to execute your app. | ||
|
|
||
| ## Useful commands | ||
|
|
||
| * `npm run build` compile typescript to js | ||
| * `npm run watch` watch for changes and compile | ||
| * `npm run test` perform the jest unit tests | ||
| * `npx cdk deploy` deploy this stack to your default AWS account/region | ||
| * `npx cdk diff` compare deployed stack with current state | ||
| * `npx cdk synth` emits the synthesized CloudFormation template |
21 changes: 21 additions & 0 deletions
21
typescript/stepfunction-external-definition/bin/stepfunction-external-definition.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env node | ||
| import 'source-map-support/register'; | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { StepfunctionExternalDefinitionStack } from '../lib/stepfunction-external-definition-stack'; | ||
|
|
||
| const app = new cdk.App(); | ||
| new StepfunctionExternalDefinitionStack(app, 'StepfunctionExternalDefinitionStack', { | ||
| /* If you don't specify 'env', this stack will be environment-agnostic. | ||
| * Account/Region-dependent features and context lookups will not work, | ||
| * but a single synthesized template can be deployed anywhere. */ | ||
|
|
||
| /* Uncomment the next line to specialize this stack for the AWS Account | ||
| * and Region that are implied by the current CLI configuration. */ | ||
| // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, | ||
|
|
||
| /* Uncomment the next line if you know exactly what Account and Region you | ||
| * want to deploy the stack to. */ | ||
| // env: { account: '123456789012', region: 'us-east-1' }, | ||
|
|
||
| /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| { | ||
| "app": "npx ts-node --prefer-ts-exts bin/stepfunction-external-definition.ts", | ||
| "watch": { | ||
| "include": [ | ||
| "**" | ||
| ], | ||
| "exclude": [ | ||
| "README.md", | ||
| "cdk*.json", | ||
| "**/*.d.ts", | ||
| "**/*.js", | ||
| "tsconfig.json", | ||
| "package*.json", | ||
| "yarn.lock", | ||
| "node_modules", | ||
| "test" | ||
| ] | ||
| }, | ||
| "context": { | ||
| "@aws-cdk/aws-lambda:recognizeLayerVersion": true, | ||
| "@aws-cdk/core:checkSecretUsage": true, | ||
| "@aws-cdk/core:target-partitions": [ | ||
| "aws", | ||
| "aws-cn" | ||
| ], | ||
| "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
| "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
| "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, | ||
| "@aws-cdk/aws-iam:minimizePolicies": true, | ||
| "@aws-cdk/core:validateSnapshotRemovalPolicy": true, | ||
| "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, | ||
| "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, | ||
| "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, | ||
| "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, | ||
| "@aws-cdk/core:enablePartitionLiterals": true, | ||
| "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, | ||
| "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, | ||
| "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, | ||
| "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, | ||
| "@aws-cdk/aws-route53-patters:useCertificate": true, | ||
| "@aws-cdk/customresources:installLatestAwsSdkDefault": false, | ||
| "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, | ||
| "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, | ||
| "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, | ||
| "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, | ||
| "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, | ||
| "@aws-cdk/aws-redshift:columnId": true, | ||
| "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, | ||
| "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, | ||
| "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, | ||
| "@aws-cdk/aws-kms:aliasNameRef": true, | ||
| "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, | ||
| "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, | ||
| "@aws-cdk/aws-efs:denyAnonymousAccess": true, | ||
| "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, | ||
| "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, | ||
| "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, | ||
| "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, | ||
| "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, | ||
| "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, | ||
| "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, | ||
| "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true, | ||
| "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true, | ||
| "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true, | ||
| "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true, | ||
| "@aws-cdk/aws-eks:nodegroupNameAttribute": true, | ||
| "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true, | ||
| "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true, | ||
| "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false, | ||
| "@aws-cdk/aws-s3:keepNotificationInImportedBucket": false, | ||
| "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true, | ||
| "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true, | ||
| "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true, | ||
| "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true, | ||
| "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true, | ||
| "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
typescript/stepfunction-external-definition/lib/stepfunction-external-definition-stack.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { Construct } from 'constructs'; | ||
| import * as apigateway from "aws-cdk-lib/aws-apigateway"; | ||
| import * as stepfunctions from "aws-cdk-lib/aws-stepfunctions"; | ||
| import * as logs from 'aws-cdk-lib/aws-logs'; | ||
| import * as iam from "aws-cdk-lib/aws-iam"; | ||
| import * as fs from "fs"; | ||
|
|
||
| export class StepfunctionExternalDefinitionStack extends cdk.Stack { | ||
| constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
| super(scope, id, props); | ||
|
|
||
| const logGroup = new logs.LogGroup(this, 'MyStateMachineLogGroup', { | ||
| logGroupName: '/aws/vendedlogs/states/MyStateMachine', | ||
| retention: logs.RetentionDays.ONE_WEEK, | ||
| }); | ||
|
|
||
| const workflow = fs.readFileSync('./workflow/stepfunction.json.asl', 'utf8'); | ||
| const stateMachine= new stepfunctions.StateMachine(this, 'MyStateMachine', { | ||
| stateMachineType: stepfunctions.StateMachineType.EXPRESS, | ||
| definitionBody: stepfunctions.DefinitionBody.fromString(workflow.toString()), | ||
| logs: { | ||
| destination: logGroup, | ||
| level: stepfunctions.LogLevel.ALL, | ||
| includeExecutionData: true, | ||
| }, | ||
| }); | ||
| stateMachine.addToRolePolicy(new iam.PolicyStatement({ | ||
| actions: [ | ||
| 'logs:CreateLogDelivery', | ||
| 'logs:GetLogDelivery', | ||
| 'logs:UpdateLogDelivery', | ||
| 'logs:DeleteLogDelivery', | ||
| 'logs:ListLogDeliveries', | ||
| 'logs:PutLogEvents', | ||
| 'logs:PutResourcePolicy', | ||
| 'logs:DescribeResourcePolicies', | ||
| 'logs:DescribeLogGroups' | ||
| ], | ||
| resources: ['*'], | ||
| })); | ||
|
|
||
| const api = new apigateway.RestApi(this, "StepFuncApi", { | ||
| restApiName: "StepFuncApi", | ||
| description: "StepFuncApi", | ||
| endpointTypes: [apigateway.EndpointType.REGIONAL] | ||
| }); | ||
| const resource = api.root.addResource("orders"); | ||
| resource.addMethod("GET", apigateway.StepFunctionsIntegration.startExecution(stateMachine)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "stepfunction-external-definition", | ||
| "version": "0.1.0", | ||
| "bin": { | ||
| "stepfunction-external-definition": "bin/stepfunction-external-definition.js" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "watch": "tsc -w", | ||
| "cdk": "cdk" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "22.5.4", | ||
| "aws-cdk": "2.162.1", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "~5.6.2" | ||
| }, | ||
| "dependencies": { | ||
| "aws-cdk-lib": "2.162.1", | ||
| "constructs": "^10.0.0", | ||
| "source-map-support": "^0.5.21" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "module": "commonjs", | ||
| "lib": [ | ||
| "es2020", | ||
| "dom" | ||
| ], | ||
| "declaration": true, | ||
| "strict": true, | ||
| "noImplicitAny": true, | ||
| "strictNullChecks": true, | ||
| "noImplicitThis": true, | ||
| "alwaysStrict": true, | ||
| "noUnusedLocals": false, | ||
| "noUnusedParameters": false, | ||
| "noImplicitReturns": true, | ||
| "noFallthroughCasesInSwitch": false, | ||
| "inlineSourceMap": true, | ||
| "inlineSources": true, | ||
| "experimentalDecorators": true, | ||
| "strictPropertyInitialization": false, | ||
| "typeRoots": [ | ||
| "./node_modules/@types" | ||
| ] | ||
| }, | ||
| "exclude": [ | ||
| "node_modules", | ||
| "cdk.out" | ||
| ] | ||
| } |
83 changes: 83 additions & 0 deletions
83
typescript/stepfunction-external-definition/workflow/stepfunction.json.asl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| { | ||
| "Comment": "smiple workflow for the car company", | ||
| "StartAt": "Order Received", | ||
| "States": { | ||
| "Order Received": { | ||
| "Comment": "Order revieved.", | ||
| "Type": "Pass", | ||
| "Next": "RiskyCustomer" | ||
| }, | ||
| "RiskyCustomer": { | ||
| "Comment": "No risky business!", | ||
| "Type": "Choice", | ||
| "Choices": [ | ||
| { | ||
| "Variable": "$.risk", | ||
| "BooleanEquals": true, | ||
| "Next": "Yes" | ||
| }, | ||
| { | ||
| "Variable": "$.risk", | ||
| "BooleanEquals": false, | ||
| "Next": "No" | ||
| } | ||
| ], | ||
| "Default": "Yes" | ||
| }, | ||
| "Yes": { | ||
| "Type": "Pass", | ||
| "Next": "organize pickup" | ||
| }, | ||
| "No": { | ||
| "Type": "Fail", | ||
| "Cause": "Not Hello World" | ||
| }, | ||
| "organize pickup": { | ||
| "Comment": "wait for client to pickup", | ||
| "Type": "Wait", | ||
| "Seconds": 3, | ||
| "Next": "wait for 6 months" | ||
| }, | ||
| "wait for 6 months": { | ||
| "Comment": "wait for 6 months", | ||
| "Type": "Wait", | ||
| "Seconds": 3, | ||
| "Next": "organize return" | ||
| }, | ||
| "organize return": { | ||
| "Comment": "wait for client to return", | ||
| "Type": "Wait", | ||
| "Seconds": 3, | ||
| "Next": "Parallel State" | ||
| }, | ||
| "Parallel State": { | ||
| "Comment": "A Parallel state can be used to create parallel branches of execution in your state machine.", | ||
| "Type": "Parallel", | ||
| "Next": "return", | ||
| "Branches": [ | ||
| { | ||
| "StartAt": "book", | ||
| "States": { | ||
| "book": { | ||
| "Type": "Pass", | ||
| "End": true | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "StartAt": "calculate damage", | ||
| "States": { | ||
| "calculate damage": { | ||
| "Type": "Pass", | ||
| "End": true | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "return": { | ||
| "Type": "Pass", | ||
| "End": true | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.