-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathcall-http-api.ts
62 lines (52 loc) · 1.91 KB
/
call-http-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2';
import * as iam from '@aws-cdk/aws-iam';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CallApiGatewayEndpointBase } from './base';
import { CallApiGatewayEndpointBaseProps } from './base-types';
/**
* Properties for calling an HTTP API Endpoint
*/
export interface CallApiGatewayHttpApiEndpointProps extends CallApiGatewayEndpointBaseProps {
/**
* API to call
*/
readonly api: apigatewayv2.IHttpApi;
/**
* Name of the stage where the API is deployed to in API Gateway
* @default '$default'
*/
readonly stageName?: string;
}
/**
* Call HTTP API endpoint as a Task
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html
*/
export class CallApiGatewayHttpApiEndpoint extends CallApiGatewayEndpointBase {
protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined;
protected readonly taskPolicies?: iam.PolicyStatement[] | undefined;
protected readonly apiEndpoint: string;
protected readonly arnForExecuteApi: string;
protected readonly stageName?: string;
constructor(scope: Construct, id: string, private readonly props: CallApiGatewayHttpApiEndpointProps) {
super(scope, id, props);
this.apiEndpoint = this.getApiEndpoint();
this.arnForExecuteApi = this.getArnForExecuteApi();
this.taskPolicies = this.createPolicyStatements();
}
private getApiEndpoint(): string {
const apiStack = cdk.Stack.of(this.props.api);
return `${this.props.api.apiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`;
}
private getArnForExecuteApi(): string {
const { api, stageName, method, apiPath } = this.props;
return cdk.Stack.of(api).formatArn({
service: 'execute-api',
resource: api.apiId,
sep: '/',
resourceName: `${stageName}/${method}${apiPath}`,
});
}
}