-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep-functions-private-api-stack.ts
More file actions
74 lines (65 loc) · 2 KB
/
Copy pathstep-functions-private-api-stack.ts
File metadata and controls
74 lines (65 loc) · 2 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
import { Construct } from 'constructs';
import { PrivateApi } from './constructs/PrivateApi';
import { Peer, Port, SecurityGroup, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Orchestration } from './constructs/Orchestration';
import { Fn, Stack, StackProps } from 'aws-cdk-lib';
import {
CfnResourceConfiguration,
CfnResourceGateway,
} from 'aws-cdk-lib/aws-vpclattice';
export class StepFunctionsPrivateApiStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const vpc = new Vpc(this, 'Vpc', {
maxAzs: 1,
natGateways: 0,
});
// Private API
const api = new PrivateApi(this, 'PrivateApi', {
vpc: vpc,
});
const rgSecurityGroup = new SecurityGroup(this, 'ResourceGatewaySG', {
vpc: vpc,
allowAllOutbound: false,
});
rgSecurityGroup.addEgressRule(
Peer.ipv4(vpc.vpcCidrBlock),
Port.tcp(443),
'Allow HTTPS traffic from Resource Gateway',
);
// Resource Gateway
const resourceGateway = new CfnResourceGateway(this, 'ResourceGateway', {
name: 'private-api-access',
ipAddressType: 'IPV4',
vpcIdentifier: vpc.vpcId,
subnetIds: vpc.isolatedSubnets.map((subnet) => subnet.subnetId),
securityGroupIds: [rgSecurityGroup.securityGroupId],
});
// Resource Configuration
const resourceConfig = new CfnResourceConfiguration(
this,
'ResourceConfig',
{
name: 'sf-private-api',
portRanges: ['443'],
resourceGatewayId: resourceGateway.ref,
resourceConfigurationType: 'SINGLE',
},
);
resourceConfig.addPropertyOverride(
'ResourceConfigurationDefinition.DnsResource',
{
DomainName: Fn.select(
1,
Fn.split(':', Fn.select(0, api.vpcEndpoint.vpcEndpointDnsEntries)),
),
IpAddressType: 'IPV4',
},
);
new Orchestration(this, 'Orchestration', {
api: api.api,
vpc: vpc,
resourceConfig: resourceConfig,
});
}
}