forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apigatewayv2): add aws service integration -- step functions
- Loading branch information
Showing
11 changed files
with
633 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
141 changes: 141 additions & 0 deletions
141
packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/aws.ts
This file contains 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,141 @@ | ||
import { IRole } from '@aws-cdk/aws-iam'; | ||
import { IStateMachine } from '@aws-cdk/aws-stepfunctions'; | ||
import { AwsServiceIntegration, AwsServiceIntegrationProps } from './private/integration'; | ||
|
||
/** | ||
* The common Step Functions integration resource for HTTP API | ||
*/ | ||
abstract class StepFunctionsIntegration extends AwsServiceIntegration { | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _integrationService(): string { | ||
return 'StepFunctions'; | ||
} | ||
} | ||
|
||
/** | ||
* Step Functions StartExecution integration properties | ||
*/ | ||
export interface StepFunctionsStartExecutionIntegrationProps extends AwsServiceIntegrationProps { | ||
|
||
/** | ||
* The state machine to be executed | ||
*/ | ||
readonly stateMachine: IStateMachine; | ||
|
||
/** | ||
* The execution name | ||
* | ||
* @default - undefined | ||
*/ | ||
readonly name?: string; | ||
|
||
/** | ||
* The input parameters of execution | ||
* | ||
* @default - undefined | ||
*/ | ||
readonly input?: any; | ||
|
||
/** | ||
* The region of state machine | ||
* | ||
* @default - undefined | ||
*/ | ||
readonly region?: string; | ||
} | ||
|
||
/** | ||
* The StepFunctions-StartExecution integration resource for HTTP API | ||
*/ | ||
export class StepFunctionsStartExecutionIntegration extends StepFunctionsIntegration { | ||
|
||
constructor(private readonly _props: StepFunctionsStartExecutionIntegrationProps) { | ||
super(_props); | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _integrationAction(): string { | ||
return 'StartExecution'; | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _fulfillRole(credentialsRole: IRole): void { | ||
this._props.stateMachine.grantStartExecution(credentialsRole); | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _buildRequestParameters(): { [key: string]: any } { | ||
return { | ||
StateMachineArn: this._props.stateMachine.stateMachineArn, | ||
Name: this._props.name, | ||
Input: this._props.input, | ||
Region: this._props.region, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Step Functions StartSyncExecution integration properties | ||
*/ | ||
export interface StepFunctionsStartSyncExecutionIntegrationProps extends StepFunctionsStartExecutionIntegrationProps { | ||
|
||
/** | ||
* Passes the AWS X-Ray trace header. The trace header can also be passed in the request payload. | ||
* | ||
* @default - undefined | ||
*/ | ||
readonly traceHeader?: string; | ||
} | ||
|
||
/** | ||
* The StepFunctions-StartExecution integration resource for HTTP API | ||
*/ | ||
export class StepFunctionsStartSyncExecutionIntegration extends StepFunctionsIntegration { | ||
|
||
constructor(private readonly _props: StepFunctionsStartSyncExecutionIntegrationProps) { | ||
super(_props); | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _integrationAction(): string { | ||
return 'StartSyncExecution'; | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _fulfillRole(credentialsRole: IRole): void { | ||
this._props.stateMachine.grantStartExecution(credentialsRole); | ||
} | ||
|
||
/** | ||
* | ||
* @internal | ||
*/ | ||
protected _buildRequestParameters(): { [key: string]: any } { | ||
return { | ||
StateMachineArn: this._props.stateMachine.stateMachineArn, | ||
Name: this._props.name, | ||
Input: this._props.input, | ||
Region: this._props.region, | ||
TraceHeader: this._props.traceHeader, | ||
}; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
82 changes: 82 additions & 0 deletions
82
packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/aws.test.ts
This file contains 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,82 @@ | ||
import '@aws-cdk/assert-internal/jest'; | ||
import { HttpApi, HttpRoute, HttpRouteKey } from '@aws-cdk/aws-apigatewayv2'; | ||
import { StateMachine, Chain, Pass, StateMachineType } from '@aws-cdk/aws-stepfunctions'; | ||
import { Stack, Duration } from '@aws-cdk/core'; | ||
import { StepFunctionsStartExecutionIntegration, StepFunctionsStartSyncExecutionIntegration } from '../../lib'; | ||
|
||
describe('AwsServiceIntegration', () => { | ||
test('StepFunctions-StartExecution', () => { | ||
const stack = new Stack(); | ||
const api = new HttpApi(stack, 'HttpApi'); | ||
|
||
new HttpRoute(stack, 'StepFunctionsStartExeRoute', { | ||
httpApi: api, | ||
integration: new StepFunctionsStartExecutionIntegration({ | ||
stateMachine: stateMachine(stack), | ||
name: 'MyExe', | ||
input: '$request.body.input', | ||
timeout: Duration.seconds(10), | ||
description: 'Start execution of state machine', | ||
}), | ||
routeKey: HttpRouteKey.with('/start'), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::ApiGatewayV2::Integration', { | ||
IntegrationType: 'AWS_PROXY', | ||
CredentialsArn: { | ||
'Fn::GetAtt': [ | ||
'StepFunctionsStartExeRouteRoleEC2F84D2', | ||
'Arn', | ||
], | ||
}, | ||
IntegrationSubtype: 'StepFunctions-StartExecution', | ||
PayloadFormatVersion: '1.0', | ||
RequestParameters: { | ||
StateMachineArn: { | ||
Ref: 'MyStateMachine6C968CA5', | ||
}, | ||
Input: '$request.body.input', | ||
Name: 'MyExe', | ||
}, | ||
TimeoutInMillis: 10000, | ||
}); | ||
}); | ||
|
||
test('StepFunctions-StartSyncExecution', () => { | ||
const stack = new Stack(); | ||
const api = new HttpApi(stack, 'HttpApi'); | ||
|
||
new HttpRoute(stack, 'StepFunctionsStartSyncExeRoute', { | ||
httpApi: api, | ||
integration: new StepFunctionsStartSyncExecutionIntegration({ | ||
stateMachine: stateMachine(stack), | ||
input: { | ||
a: 'b', | ||
}, | ||
}), | ||
routeKey: HttpRouteKey.with('/startSync'), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::ApiGatewayV2::Integration', { | ||
IntegrationType: 'AWS_PROXY', | ||
IntegrationSubtype: 'StepFunctions-StartSyncExecution', | ||
PayloadFormatVersion: '1.0', | ||
RequestParameters: { | ||
StateMachineArn: { | ||
Ref: 'MyStateMachine6C968CA5', | ||
}, | ||
Input: { | ||
a: 'b', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
function stateMachine(stack: Stack): StateMachine { | ||
return new StateMachine(stack, 'MyStateMachine', { | ||
stateMachineName: 'MyStateMachine', | ||
definition: Chain.start(new Pass(stack, 'Pass')), | ||
stateMachineType: StateMachineType.STANDARD, | ||
}); | ||
} |
Oops, something went wrong.