1+ import { Construct } from '@aws-cdk/core' ;
2+ import { TaskDefinition } from '../base/task-definition' ;
3+ import { CfnTaskDefinition } from '../ecs.generated' ;
4+ import { ProxyConfiguration } from './proxy-configuration' ;
5+
6+ /**
7+ * Interface for setting the properties of proxy configuration.
8+ */
9+ export interface AppMeshProxyConfigurationProps {
10+ /**
11+ * The user ID (UID) of the proxy container as defined by the user parameter in a container definition.
12+ * This is used to ensure the proxy ignores its own traffic. If IgnoredGID is specified, this field can be empty.
13+ */
14+ readonly ignoredUID ?: number ;
15+
16+ /**
17+ * The group ID (GID) of the proxy container as defined by the user parameter in a container definition.
18+ * This is used to ensure the proxy ignores its own traffic. If IgnoredUID is specified, this field can be empty.
19+ */
20+ readonly ignoredGID ?: number ;
21+
22+ /**
23+ * The list of ports that the application uses.
24+ * Network traffic to these ports is forwarded to the ProxyIngressPort and ProxyEgressPort.
25+ */
26+ readonly appPorts : number [ ] ;
27+
28+ /**
29+ * Specifies the port that incoming traffic to the AppPorts is directed to.
30+ */
31+ readonly proxyIngressPort : number ;
32+
33+ /**
34+ * Specifies the port that outgoing traffic from the AppPorts is directed to.
35+ */
36+ readonly proxyEgressPort : number ;
37+
38+ /**
39+ * The egress traffic going to these specified ports is ignored and not redirected to the ProxyEgressPort. It can be an empty list.
40+ */
41+ readonly egressIgnoredPorts ?: number [ ] ;
42+
43+ /**
44+ * The egress traffic going to these specified IP addresses is ignored and not redirected to the ProxyEgressPort. It can be an empty list.
45+ */
46+ readonly egressIgnoredIPs ?: string [ ] ;
47+ }
48+
49+ /**
50+ * The configuration to use when setting an App Mesh proxy configuration.
51+ */
52+ export interface AppMeshProxyConfigurationConfigProps {
53+ /**
54+ * The name of the container that will serve as the App Mesh proxy.
55+ */
56+ readonly containerName : string ;
57+
58+ /**
59+ * The set of network configuration parameters to provide the Container Network Interface (CNI) plugin.
60+ */
61+ readonly properties : AppMeshProxyConfigurationProps ;
62+ }
63+
64+ /**
65+ * The class for App Mesh proxy configurations.
66+ *
67+ * For tasks using the EC2 launch type, the container instances require at least version 1.26.0 of the container agent and at least version
68+ * 1.26.0-1 of the ecs-init package to enable a proxy configuration. If your container instances are launched from the Amazon ECS-optimized
69+ * AMI version 20190301 or later, then they contain the required versions of the container agent and ecs-init.
70+ * For more information, see [Amazon ECS-optimized AMIs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html).
71+ *
72+ * For tasks using the Fargate launch type, the task or service requires platform version 1.3.0 or later.
73+ */
74+ export class AppMeshProxyConfiguration extends ProxyConfiguration {
75+ /**
76+ * Constructs a new instance of the AppMeshProxyConfiguration class.
77+ */
78+ constructor ( private readonly props : AppMeshProxyConfigurationConfigProps ) {
79+ super ( ) ;
80+ if ( props . properties ) {
81+ if ( ! props . properties . ignoredUID && ! props . properties . ignoredGID ) {
82+ throw new Error ( "At least one of ignoredUID or ignoredGID should be specified." ) ;
83+ }
84+ }
85+ }
86+
87+ /**
88+ * Called when the proxy configuration is configured on a task definition.
89+ */
90+ public bind ( _scope : Construct , _taskDefinition : TaskDefinition ) : CfnTaskDefinition . ProxyConfigurationProperty {
91+ const configProps = this . props . properties ;
92+ const configType = "APPMESH" ;
93+ return {
94+ containerName : this . props . containerName ,
95+ proxyConfigurationProperties : renderProperties ( configProps ) ,
96+ type : configType
97+ } ;
98+ }
99+ }
100+
101+ function renderProperties ( props : AppMeshProxyConfigurationProps ) : CfnTaskDefinition . KeyValuePairProperty [ ] {
102+ const ret = [ ] ;
103+ for ( const [ k , v ] of Object . entries ( props ) ) {
104+ const key = String ( k ) ;
105+ const value = String ( v ) ;
106+ if ( value !== "undefined" && value !== "" ) {
107+ const capitalizedKey = key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 ) ;
108+ ret . push ( { [ "name" ] : capitalizedKey , [ "value" ] : value } ) ;
109+ }
110+ }
111+ return ret ;
112+ }
0 commit comments