cdk api gateway endpoint type specification using if-condition #20397
Replies: 1 comment
-
ISSUE SOLVEDIntrinsic functions like if are unfortunately not supported in the L2 construct SpecRestApi, however, you can directly access the CfnRestApi L1 resource via On the L1 construct resource you can directly access desired properties, such as endpoint_configuration, parameters, ... And use the intrinsic function in there. See the snippet below.
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I want to assign different type of an API gateway endpoint based on a condition, here IsGlobalPartition. However, I am encountering a problem with required types for endpoint_type property.
I am using L2 construct SpecRestApi to build the RestApi.
api_gateway = apigateway.SpecRestApi(self, 'v1-s2a-metadata-datapoints', api_definition=apigateway.ApiDefinition.from_asset('cdk/api_gateway/restApi.yaml'), deploy=True, deploy_options=stage_options, domain_name=domain_name_options, endpoint_types=[cdk.Fn.condition_if('isGlobalPartition', apigateway.EndpointType.EDGE, apigateway.EndpointType.REGIONAL).to_string()] )
Error:
jsii.errors.JSIIError: Expected enum value, got "${Token[TOKEN.207]}"
I would need it to look like this:
ApiGatewayv1s2ametadatadatapointsC3B22D32: Type: AWS::ApiGateway::RestApi Properties: ApiKeySourceType: HEADER BinaryMediaTypes: - application~1octet-stream EndpointConfiguration: Fn::If: - isGlobalPartition - Ref: AWS::NoValue - - REGIONAL Name: v1-s2a-metadata-datapoints Parameters: endpointConfigurationTypes: Fn::If: - isGlobalPartition - Ref: AWS::NoValue - REGIONAL Metadata: aws:cdk:path: DatapointsStack/ApiGateway/v1-s2a-metadata-datapoints
If anyone had an experience or an idea how to deal with if conditions and type checking in general, help would be highly appreciated.
P.S. The condition is necessary and cannot be omitted because its boolean value gets evaluated during stack building.
Beta Was this translation helpful? Give feedback.
All reactions