Reputation: 1262
I have the below cdk in python for building my API
domain_name = _apigateway.DomainNameOptions(
certificate=certificate,
domain_name=custom_domain_name,
mtls={
"bucket": _s3.Bucket.from_bucket_arn(self, 'BucketByArn', mtls_bucket_arn),
"key": mtls_bucket_key
},
security_policy=_apigateway.SecurityPolicy("TLS_1_2")
)
api_01 = _apigateway.LambdaRestApi(
self,
api_id,
rest_api_name=rest_api_name,
domain_name=domain_name,
handler=measurements_fn,
deploy_options=_apigateway.StageOptions(stage_name=stage),
proxy=False
)
api_01.node.default_child.add_property_override(
"DisableExecuteApiEndpoint",
"true"
)
with 2 endpoints attached to the api and i would like to create an API Mapping. Based on the documentation i see that i should use _apigatewayv2.ApiMapping
_apigatewayv2.ApiMapping(
self,
id='someId',
api=api_01,
api_mapping_key='api/1.0',
domain_name=domain_name
)
but the domain_name option fails due to
Expected object reference, got {"$jsii.struct":{"fqn":"@aws-cdk/aws-apigateway.DomainNameOptions"
The case is that i need the DomainNameOptions because i'm using LambdaRestApi which based on the documentation expects such an object.
Any idea on how to implement API Mapping for my case?
Upvotes: 1
Views: 1815
Reputation: 2400
If you look at the documentation for aws_apigatewayv2.ApiMapping
and at the domain_name object you can see it is expecting an iDomainName
object - so you have to find an appropriate object that has the same interface hook. However, if you click on that in the doc, it takes you to here - an apigatewayv2 iDomainName interface rather than the DomainNameOptions original version. (which is in the apigateway module rather than the apigatewayv2 module)
All this is to say... your crossing libraries and that doesn't always work like expected, and on top of that the apigatewayv2 is experimental, prone to some integration issues, and may change tomorrow.
As you are attempting to make use of a Rest API connected to a Lambda, then the apigateway (not v2) module should be enough. (the apigatewayv2 is more for the experimental HTTP api's to lambda)
Using only aws_apigateway
module you can accomplish this with something like:
my_domain = _apigateway.DomainName(
self, "MyDomain",
domain_name=my_domain_name)
my_domain.add_base_path_mapping(
target_api= my_api, # a aws_apigateway.RestApi() object
)
Then you'll want to make sure your route53 ARecord is updated as well, or the dns will not apply to your custom domain. (this is using the `aws_route53 and aws_route53_targets modules)
_route53.ARecord(
self, "MyDomainAliasRecord",
zone=my_route53_zone, # a aws_route53.HostedZone() Object
target=my_route_53_target # a aws_route53.RecordTarget() object),
record_name=my_domain_name
)
Upvotes: 3