konokenj.cdk-api-mcp-server 0.45.0__py3-none-any.whl → 0.46.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of konokenj.cdk-api-mcp-server might be problematic. Click here for more details.
- cdk_api_mcp_server/__about__.py +1 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/custom-resource-handlers/README.md +15 -78
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codedeploy/integ.deployment-config.ts +4 -15
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codedeploy/integ.deployment-group.ts +218 -40
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.availability-zone-rebalancing.ts +14 -4
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.enable-execute-command.ts +35 -29
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.exec-command.ts +16 -22
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.lb-awsvpc-nw.ts +26 -16
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.pseudo-terminal.ts +18 -8
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke-jsonata.ts +80 -87
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke.ts +69 -87
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.start-job-run.ts +43 -96
- {konokenj_cdk_api_mcp_server-0.45.0.dist-info → konokenj_cdk_api_mcp_server-0.46.0.dist-info}/METADATA +2 -2
- {konokenj_cdk_api_mcp_server-0.45.0.dist-info → konokenj_cdk_api_mcp_server-0.46.0.dist-info}/RECORD +17 -17
- {konokenj_cdk_api_mcp_server-0.45.0.dist-info → konokenj_cdk_api_mcp_server-0.46.0.dist-info}/WHEEL +0 -0
- {konokenj_cdk_api_mcp_server-0.45.0.dist-info → konokenj_cdk_api_mcp_server-0.46.0.dist-info}/entry_points.txt +0 -0
- {konokenj_cdk_api_mcp_server-0.45.0.dist-info → konokenj_cdk_api_mcp_server-0.46.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -3,38 +3,48 @@ import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
|
|
|
3
3
|
import * as cdk from 'aws-cdk-lib';
|
|
4
4
|
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
5
5
|
|
|
6
|
-
const app = new cdk.App(
|
|
6
|
+
const app = new cdk.App({
|
|
7
|
+
postCliContext: {
|
|
8
|
+
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
|
|
9
|
+
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
|
|
10
|
+
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
|
|
11
|
+
'@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy': false,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
7
14
|
const stack = new cdk.Stack(app, 'aws-ecs-integ');
|
|
8
15
|
|
|
9
16
|
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
|
|
10
17
|
|
|
11
|
-
const cluster = new ecs.Cluster(stack, '
|
|
18
|
+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
|
|
19
|
+
cluster.addCapacity('DefaultAutoScalingGroup', {
|
|
20
|
+
instanceType: new ec2.InstanceType('t2.micro'),
|
|
21
|
+
});
|
|
12
22
|
|
|
13
|
-
const taskDefinition = new ecs.
|
|
14
|
-
|
|
15
|
-
cpu: 512,
|
|
23
|
+
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef', {
|
|
24
|
+
networkMode: ecs.NetworkMode.AWS_VPC,
|
|
16
25
|
});
|
|
17
26
|
|
|
18
|
-
taskDefinition.addContainer('web', {
|
|
27
|
+
const container = taskDefinition.addContainer('web', {
|
|
19
28
|
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
29
|
+
memoryLimitMiB: 256,
|
|
30
|
+
environment: {
|
|
31
|
+
SOME_VARIABLE: 'value',
|
|
32
|
+
},
|
|
24
33
|
});
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
container.addPortMappings({
|
|
36
|
+
containerPort: 80,
|
|
37
|
+
protocol: ecs.Protocol.TCP,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const service = new ecs.Ec2Service(stack, 'Service', {
|
|
27
41
|
cluster,
|
|
28
42
|
taskDefinition,
|
|
29
43
|
});
|
|
30
44
|
|
|
31
|
-
const scaling = service.autoScaleTaskCount({ maxCapacity: 10 });
|
|
32
|
-
// Quite low to try and force it to scale
|
|
33
|
-
scaling.scaleOnCpuUtilization('ReasonableCpu', { targetUtilizationPercent: 10 });
|
|
34
|
-
|
|
35
45
|
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc, internetFacing: true });
|
|
36
46
|
const listener = lb.addListener('PublicListener', { port: 80, open: true });
|
|
37
|
-
listener.addTargets('
|
|
47
|
+
listener.addTargets('ECS', {
|
|
38
48
|
port: 80,
|
|
39
49
|
targets: [service],
|
|
40
50
|
});
|
cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.pseudo-terminal.ts
CHANGED
|
@@ -3,25 +3,35 @@ import * as cdk from 'aws-cdk-lib';
|
|
|
3
3
|
import * as integ from '@aws-cdk/integ-tests-alpha';
|
|
4
4
|
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
5
5
|
|
|
6
|
-
const app = new cdk.App(
|
|
7
|
-
|
|
6
|
+
const app = new cdk.App({
|
|
7
|
+
postCliContext: {
|
|
8
|
+
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
|
|
9
|
+
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
|
|
10
|
+
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
|
|
11
|
+
'@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy': false,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const stack = new cdk.Stack(app, 'aws-ecs-integ-pseudo-terminal');
|
|
8
15
|
|
|
9
16
|
// Create a cluster
|
|
10
17
|
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
|
|
11
18
|
|
|
12
19
|
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
cluster.addCapacity('DefaultAutoScalingGroup', {
|
|
21
|
+
instanceType: new ec2.InstanceType('t2.micro'),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef', {
|
|
25
|
+
networkMode: ecs.NetworkMode.AWS_VPC,
|
|
16
26
|
});
|
|
27
|
+
|
|
17
28
|
taskDefinition.addContainer('web', {
|
|
18
29
|
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
|
|
19
|
-
memoryLimitMiB:
|
|
20
|
-
cpu: 256,
|
|
30
|
+
memoryLimitMiB: 256,
|
|
21
31
|
pseudoTerminal: true,
|
|
22
32
|
});
|
|
23
33
|
|
|
24
|
-
new ecs.
|
|
34
|
+
new ecs.Ec2Service(stack, 'Service', {
|
|
25
35
|
cluster,
|
|
26
36
|
taskDefinition,
|
|
27
37
|
});
|
|
@@ -1,119 +1,112 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
3
|
-
import * as cdk from 'aws-cdk-lib';
|
|
4
|
-
import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
1
|
+
import * as path from 'path';
|
|
5
2
|
import { IntegTest, ExpectedResult } from '@aws-cdk/integ-tests-alpha';
|
|
6
|
-
import
|
|
3
|
+
import * as cdk from 'aws-cdk-lib';
|
|
4
|
+
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
|
|
5
|
+
import * as events from 'aws-cdk-lib/aws-events';
|
|
6
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
7
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
8
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
9
|
+
import { password, username } from './my-lambda-handler';
|
|
7
10
|
|
|
8
11
|
/*
|
|
9
|
-
* Creates
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Stack verification steps:
|
|
14
|
-
* The generated State Machine can be executed from the CLI (or Step Functions console)
|
|
15
|
-
* and runs with an execution status of `Succeeded`.
|
|
12
|
+
* Creates an API Gateway instance with a GET method and mock integration,
|
|
13
|
+
* secured with basic auth. It then creates a matching Connection and uses it
|
|
14
|
+
* in a state machine with a task state to invoke the endpoint.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Stack verification steps :
|
|
17
|
+
* * aws stepfunctions start-execution --state-machine-arn <deployed state machine arn> : should return execution arn
|
|
18
|
+
* * aws stepfunctions describe-execution --execution-arn <execution-arn generated before> : should return status as SUCCEEDED
|
|
19
19
|
*/
|
|
20
20
|
const app = new cdk.App({
|
|
21
21
|
postCliContext: {
|
|
22
22
|
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
|
-
const stack = new cdk.Stack(app, 'aws-stepfunctions-tasks-
|
|
25
|
+
const stack = new cdk.Stack(app, 'aws-stepfunctions-tasks-http-invoke-integ');
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
statusCode: '200',
|
|
31
|
-
body: 'hello, world!',
|
|
32
|
-
...event,
|
|
33
|
-
};
|
|
34
|
-
};`),
|
|
35
|
-
runtime: STANDARD_NODEJS_RUNTIME,
|
|
36
|
-
handler: 'index.handler',
|
|
27
|
+
const authorizerHandler = new lambda.NodejsFunction(stack, 'AuthorizerHandler', {
|
|
28
|
+
entry: path.resolve(__dirname, 'my-lambda-handler', 'index.ts'),
|
|
29
|
+
handler: 'handler',
|
|
37
30
|
});
|
|
38
31
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
execInput: '{% $states.context.Execution.Input %}',
|
|
44
|
-
execName: '{% $states.context.Execution.Name %}',
|
|
45
|
-
execRoleArn: '{% $states.context.Execution.RoleArn %}',
|
|
46
|
-
execStartTime: '{% $states.context.Execution.StartTime %}',
|
|
47
|
-
stateEnteredTime: '{% $states.context.State.EnteredTime %}',
|
|
48
|
-
stateName: '{% $states.context.State.Name %}',
|
|
49
|
-
stateRetryCount: '{% $states.context.State.RetryCount %}',
|
|
50
|
-
stateMachineId: '{% $states.context.StateMachine.Id %}',
|
|
51
|
-
stateMachineName: '{% $states.context.StateMachine.Name %}',
|
|
52
|
-
}),
|
|
53
|
-
outputs: '{% $states.result.Payload %}',
|
|
32
|
+
const authorizer = new apigateway.TokenAuthorizer(stack, 'Authorizer', {
|
|
33
|
+
handler: authorizerHandler,
|
|
34
|
+
identitySource: 'method.request.header.Authorization',
|
|
35
|
+
resultsCacheTtl: cdk.Duration.seconds(0),
|
|
54
36
|
});
|
|
55
37
|
|
|
56
|
-
const
|
|
57
|
-
code: Code.fromInline(`exports.handler = async function(event, context) {
|
|
58
|
-
const expectedFields = [
|
|
59
|
-
'execId', 'execInput', 'execName', 'execRoleArn',
|
|
60
|
-
'execStartTime', 'stateEnteredTime', 'stateName',
|
|
61
|
-
'stateRetryCount', 'stateMachineId', 'stateMachineName',
|
|
62
|
-
];
|
|
63
|
-
const fieldsAreSet = expectedFields.every(field => event[field] !== undefined);
|
|
64
|
-
return {
|
|
65
|
-
status: event.statusCode === '200' && fieldsAreSet ? 'SUCCEEDED' : 'FAILED'
|
|
66
|
-
};
|
|
67
|
-
};`),
|
|
68
|
-
runtime: STANDARD_NODEJS_RUNTIME,
|
|
69
|
-
handler: 'index.handler',
|
|
70
|
-
});
|
|
38
|
+
const api = new apigateway.RestApi(stack, 'IntegRestApi');
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
api.root.addResource('test').addMethod(
|
|
41
|
+
'GET',
|
|
42
|
+
new apigateway.MockIntegration({
|
|
43
|
+
integrationResponses: [
|
|
44
|
+
{
|
|
45
|
+
statusCode: '200',
|
|
46
|
+
responseTemplates: {
|
|
47
|
+
'application/json': JSON.stringify({ message: 'Hello, tester!' }),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
passthroughBehavior: apigateway.PassthroughBehavior.NEVER,
|
|
52
|
+
requestTemplates: {
|
|
53
|
+
'application/json': '{ "statusCode": 200 }',
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
{
|
|
57
|
+
authorizer,
|
|
58
|
+
methodResponses: [
|
|
59
|
+
{
|
|
60
|
+
statusCode: '200',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
76
63
|
},
|
|
77
|
-
|
|
64
|
+
);
|
|
78
65
|
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
cause: 'Job Failed',
|
|
82
|
-
error: 'Received a status that was not 200',
|
|
66
|
+
const connection = new events.Connection(stack, 'Connection', {
|
|
67
|
+
authorization: events.Authorization.basic(username, cdk.SecretValue.unsafePlainText(password)),
|
|
83
68
|
});
|
|
84
|
-
const finalStatus = sfn.Pass.jsonata(stack, 'Final step');
|
|
85
69
|
|
|
86
|
-
const
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
const httpInvokeTask = tasks.HttpInvoke.jsonata(stack, 'Invoke HTTP Endpoint', {
|
|
71
|
+
apiRoot: api.urlForPath('/'),
|
|
72
|
+
apiEndpoint: sfn.TaskInput.fromText('{% $states.input.apiEndpoint %}'),
|
|
73
|
+
connection,
|
|
74
|
+
method: sfn.TaskInput.fromText('GET'),
|
|
75
|
+
outputs: {
|
|
76
|
+
ResponseBody: '{% $states.result.ResponseBody %}',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
93
79
|
|
|
94
80
|
const sm = new sfn.StateMachine(stack, 'StateMachine', {
|
|
95
|
-
definition:
|
|
81
|
+
definition: httpInvokeTask,
|
|
96
82
|
timeout: cdk.Duration.seconds(30),
|
|
97
83
|
});
|
|
98
84
|
|
|
99
|
-
new
|
|
100
|
-
value: sm.stateMachineArn,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const integ = new IntegTest(app, 'IntegTest', {
|
|
85
|
+
const testCase = new IntegTest(app, 'HttpInvokeTest', {
|
|
104
86
|
testCases: [stack],
|
|
105
87
|
});
|
|
106
|
-
|
|
88
|
+
|
|
89
|
+
// Start an execution
|
|
90
|
+
const start = testCase.assertions.awsApiCall('@aws-sdk/client-sfn', 'StartExecution', {
|
|
107
91
|
stateMachineArn: sm.stateMachineArn,
|
|
92
|
+
input: JSON.stringify({
|
|
93
|
+
apiEndpoint: '/test',
|
|
94
|
+
}),
|
|
108
95
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
status: 'SUCCEEDED',
|
|
114
|
-
})).waitForAssertions({
|
|
115
|
-
totalTimeout: cdk.Duration.seconds(10),
|
|
116
|
-
interval: cdk.Duration.seconds(3),
|
|
96
|
+
|
|
97
|
+
// describe the results of the execution
|
|
98
|
+
const describe = testCase.assertions.awsApiCall('@aws-sdk/client-sfn', 'DescribeExecution', {
|
|
99
|
+
executionArn: start.getAttString('executionArn'),
|
|
117
100
|
});
|
|
118
101
|
|
|
102
|
+
// assert the results
|
|
103
|
+
describe.expect(ExpectedResult.objectLike({
|
|
104
|
+
status: 'SUCCEEDED',
|
|
105
|
+
output: JSON.stringify({
|
|
106
|
+
ResponseBody: {
|
|
107
|
+
message: 'Hello, tester!',
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
}));
|
|
111
|
+
|
|
119
112
|
app.synth();
|
cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke.ts
CHANGED
|
@@ -1,119 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
3
|
-
import * as cdk from 'aws-cdk-lib';
|
|
4
|
-
import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
1
|
+
import * as path from 'path';
|
|
5
2
|
import { IntegTest, ExpectedResult } from '@aws-cdk/integ-tests-alpha';
|
|
6
|
-
import
|
|
3
|
+
import * as cdk from 'aws-cdk-lib';
|
|
4
|
+
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
|
|
5
|
+
import * as events from 'aws-cdk-lib/aws-events';
|
|
6
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
7
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
8
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
9
|
+
import { password, username } from './my-lambda-handler';
|
|
7
10
|
|
|
8
11
|
/*
|
|
9
|
-
* Creates
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Stack verification steps:
|
|
14
|
-
* The generated State Machine can be executed from the CLI (or Step Functions console)
|
|
15
|
-
* and runs with an execution status of `Succeeded`.
|
|
12
|
+
* Creates an API Gateway instance with a GET method and mock integration,
|
|
13
|
+
* secured with basic auth. It then creates a matching Connection and uses it
|
|
14
|
+
* in a state machine with a task state to invoke the endpoint.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Stack verification steps :
|
|
17
|
+
* * aws stepfunctions start-execution --state-machine-arn <deployed state machine arn> : should return execution arn
|
|
18
|
+
* * aws stepfunctions describe-execution --execution-arn <execution-arn generated before> : should return status as SUCCEEDED
|
|
19
19
|
*/
|
|
20
20
|
const app = new cdk.App({
|
|
21
21
|
postCliContext: {
|
|
22
22
|
'@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
|
-
const stack = new cdk.Stack(app, 'aws-stepfunctions-tasks-
|
|
25
|
+
const stack = new cdk.Stack(app, 'aws-stepfunctions-tasks-http-invoke-integ');
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
statusCode: '200',
|
|
31
|
-
body: 'hello, world!',
|
|
32
|
-
...event,
|
|
33
|
-
};
|
|
34
|
-
};`),
|
|
35
|
-
runtime: STANDARD_NODEJS_RUNTIME,
|
|
36
|
-
handler: 'index.handler',
|
|
27
|
+
const authorizerHandler = new lambda.NodejsFunction(stack, 'AuthorizerHandler', {
|
|
28
|
+
entry: path.resolve(__dirname, 'my-lambda-handler', 'index.ts'),
|
|
29
|
+
handler: 'handler',
|
|
37
30
|
});
|
|
38
31
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
execInput: sfn.JsonPath.executionInput,
|
|
44
|
-
execName: sfn.JsonPath.executionName,
|
|
45
|
-
execRoleArn: sfn.JsonPath.executionRoleArn,
|
|
46
|
-
execStartTime: sfn.JsonPath.executionStartTime,
|
|
47
|
-
stateEnteredTime: sfn.JsonPath.stateEnteredTime,
|
|
48
|
-
stateName: sfn.JsonPath.stateName,
|
|
49
|
-
stateRetryCount: sfn.JsonPath.stateRetryCount,
|
|
50
|
-
stateMachineId: sfn.JsonPath.stateMachineId,
|
|
51
|
-
stateMachineName: sfn.JsonPath.stateMachineName,
|
|
52
|
-
}),
|
|
53
|
-
outputPath: '$.Payload',
|
|
32
|
+
const authorizer = new apigateway.TokenAuthorizer(stack, 'Authorizer', {
|
|
33
|
+
handler: authorizerHandler,
|
|
34
|
+
identitySource: 'method.request.header.Authorization',
|
|
35
|
+
resultsCacheTtl: cdk.Duration.seconds(0),
|
|
54
36
|
});
|
|
55
37
|
|
|
56
|
-
const
|
|
57
|
-
code: Code.fromInline(`exports.handler = async function(event, context) {
|
|
58
|
-
const expectedFields = [
|
|
59
|
-
'execId', 'execInput', 'execName', 'execRoleArn',
|
|
60
|
-
'execStartTime', 'stateEnteredTime', 'stateName',
|
|
61
|
-
'stateRetryCount', 'stateMachineId', 'stateMachineName',
|
|
62
|
-
];
|
|
63
|
-
const fieldsAreSet = expectedFields.every(field => event[field] !== undefined);
|
|
64
|
-
return {
|
|
65
|
-
status: event.statusCode === '200' && fieldsAreSet ? 'SUCCEEDED' : 'FAILED'
|
|
66
|
-
};
|
|
67
|
-
};`),
|
|
68
|
-
runtime: STANDARD_NODEJS_RUNTIME,
|
|
69
|
-
handler: 'index.handler',
|
|
70
|
-
});
|
|
38
|
+
const api = new apigateway.RestApi(stack, 'IntegRestApi');
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
api.root.addResource('test').addMethod(
|
|
41
|
+
'GET',
|
|
42
|
+
new apigateway.MockIntegration({
|
|
43
|
+
integrationResponses: [
|
|
44
|
+
{
|
|
45
|
+
statusCode: '200',
|
|
46
|
+
responseTemplates: {
|
|
47
|
+
'application/json': JSON.stringify({ message: 'Hello, tester!' }),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
passthroughBehavior: apigateway.PassthroughBehavior.NEVER,
|
|
52
|
+
requestTemplates: {
|
|
53
|
+
'application/json': '{ "statusCode": 200 }',
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
{
|
|
57
|
+
authorizer,
|
|
58
|
+
methodResponses: [
|
|
59
|
+
{
|
|
60
|
+
statusCode: '200',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
76
63
|
},
|
|
77
|
-
|
|
64
|
+
);
|
|
78
65
|
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
cause: 'Job Failed',
|
|
82
|
-
error: 'Received a status that was not 200',
|
|
66
|
+
const connection = new events.Connection(stack, 'Connection', {
|
|
67
|
+
authorization: events.Authorization.basic(username, cdk.SecretValue.unsafePlainText(password)),
|
|
83
68
|
});
|
|
84
|
-
const finalStatus = new sfn.Pass(stack, 'Final step');
|
|
85
69
|
|
|
86
|
-
const
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
);
|
|
70
|
+
const httpInvokeTask = new tasks.HttpInvoke(stack, 'Invoke HTTP Endpoint', {
|
|
71
|
+
apiRoot: api.urlForPath('/'),
|
|
72
|
+
apiEndpoint: sfn.TaskInput.fromText('/test'),
|
|
73
|
+
connection,
|
|
74
|
+
method: sfn.TaskInput.fromText('GET'),
|
|
75
|
+
});
|
|
93
76
|
|
|
94
77
|
const sm = new sfn.StateMachine(stack, 'StateMachine', {
|
|
95
|
-
definition:
|
|
78
|
+
definition: httpInvokeTask,
|
|
96
79
|
timeout: cdk.Duration.seconds(30),
|
|
97
80
|
});
|
|
98
81
|
|
|
99
|
-
new
|
|
100
|
-
value: sm.stateMachineArn,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const integ = new IntegTest(app, 'IntegTest', {
|
|
82
|
+
const testCase = new IntegTest(app, 'HttpInvokeTest', {
|
|
104
83
|
testCases: [stack],
|
|
105
84
|
});
|
|
106
|
-
|
|
85
|
+
|
|
86
|
+
// Start an execution
|
|
87
|
+
const start = testCase.assertions.awsApiCall('StepFunctions', 'startExecution', {
|
|
107
88
|
stateMachineArn: sm.stateMachineArn,
|
|
108
89
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
status: 'SUCCEEDED',
|
|
114
|
-
})).waitForAssertions({
|
|
115
|
-
totalTimeout: cdk.Duration.seconds(10),
|
|
116
|
-
interval: cdk.Duration.seconds(3),
|
|
90
|
+
|
|
91
|
+
// describe the results of the execution
|
|
92
|
+
const describe = testCase.assertions.awsApiCall('StepFunctions', 'describeExecution', {
|
|
93
|
+
executionArn: start.getAttString('executionArn'),
|
|
117
94
|
});
|
|
118
95
|
|
|
96
|
+
// assert the results
|
|
97
|
+
describe.expect(ExpectedResult.objectLike({
|
|
98
|
+
status: 'SUCCEEDED',
|
|
99
|
+
}));
|
|
100
|
+
|
|
119
101
|
app.synth();
|