SpecRestApi L2 construct
Represents a REST API in Amazon API Gateway, created with an OpenAPI specification.
Some properties normally accessible on
Example
const api = new apigateway.SpecRestApi(this, 'books-api', {
apiDefinition: apigateway.ApiDefinition.fromAsset('path-to-file.json'),
mode: apigateway.RestApiMode.MERGE
});
api = apigateway.SpecRestApi(self, "books-api",
api_definition=apigateway.ApiDefinition.from_asset("path-to-file.json"),
mode=apigateway.RestApiMode.MERGE
)
SpecRestApi api = SpecRestApi.Builder.create(this, "books-api")
.apiDefinition(ApiDefinition.fromAsset("path-to-file.json"))
.mode(RestApiMode.MERGE)
.build();
// Install: dotnet add package Amazon.CDK.Lib
var api = new SpecRestApi(this, "books-api", new SpecRestApiProps {
ApiDefinition = ApiDefinition.FromAsset("path-to-file.json"),
Mode = RestApiMode.MERGE
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
api := apigateway.NewSpecRestApi(this, jsii.String("books-api"), &SpecRestApiProps{
ApiDefinition: apigateway.ApiDefinition_FromAsset(jsii.String("path-to-file.json")),
Mode: apigateway.RestApiMode_MERGE,
})
Initializer
new SpecRestApi(scope: Construct, id: string, props: SpecRestApiProps)
SpecRestApi(scope: Construct, id: str, props: SpecRestApiProps)
new SpecRestApi(Construct scope, String id, SpecRestApiProps props)
new SpecRestApi(Construct scope, string id, SpecRestApiProps props)
NewSpecRestApi(Scope Construct, Id *string, Props SpecRestApiProps)
Construct Props
apiDefinitionApiDefinitionapi_definitionApiDefinitionapiDefinitionApiDefinitionApiDefinitionApiDefinitionApiDefinitionApiDefinitionrequired#binaryMediaTypesstring[]binary_media_typestyping.List[str]binaryMediaTypesList<String>BinaryMediaTypesstring[]BinaryMediaTypes*[]*string= SpecRestApi supports only UTF-8-…#default
Default: SpecRestApi supports only UTF-8-encoded text payloads.
cloudWatchRolebooleancloud_watch_roleboolcloudWatchRoleBooleanCloudWatchRoleboolCloudWatchRole*bool= false if `@aws-cdk/aws-apigatewa…#default
Default: false if @aws-cdk/aws-apigateway:disableCloudWatchRole is enabled, true otherwise
cloudWatchRoleRemovalPolicyRemovalPolicycloud_watch_role_removal_policyRemovalPolicycloudWatchRoleRemovalPolicyRemovalPolicyCloudWatchRoleRemovalPolicyRemovalPolicyCloudWatchRoleRemovalPolicyRemovalPolicy= RemovalPolicy.RETAIN#Requires cloudWatchRole to be enabled.
notes
Since API Gateway deployments are immutable, When this option is enabled (by default), an AWS::ApiGateway::Deployment resource will automatically created with a logical ID that hashes the API model (methods, resources and options). This means that when the model changes, the logical ID of this CloudFormation resource will change, and a new deployment will be created.
If this is set, latestDeployment will refer to the Deployment object and deploymentStage will refer to a Stage that points to this deployment. To customize the stage options, use the deployOptions property.
A CloudFormation Output will also be defined with the root URL endpoint of this REST API.
deployOptionsStageOptionsdeploy_optionsStageOptionsdeployOptionsStageOptionsDeployOptionsStageOptionsDeployOptionsStageOptions= Based on defaults of `StageOptio…#If deploy is disabled, this value cannot be set.
default
Default: Based on defaults of StageOptions.
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= 'Automatically created by the Re…#default
Default: 'Automatically created by the RestApi construct'
disableExecuteApiEndpointbooleandisable_execute_api_endpointbooldisableExecuteApiEndpointBooleanDisableExecuteApiEndpointboolDisableExecuteApiEndpoint*bool= false#To require that clients use a custom domain name to invoke the API, disable the default endpoint.
domainNameDomainNameOptionsdomain_nameDomainNameOptionsdomainNameDomainNameOptionsDomainNameDomainNameOptionsDomainNameDomainNameOptions= no domain name is defined, use `…#default
Default: no domain name is defined, use addDomainName or directly define a DomainName.
endpointConfigurationEndpointConfigurationendpoint_configurationEndpointConfigurationendpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfiguration= EndpointType.EDGE#endpointExportNamestringendpoint_export_namestrendpointExportNameStringEndpointExportNamestringEndpointExportName*string= when no export name is given, ou…#default
Default: when no export name is given, output will be created without export
endpointTypesEndpointType[]endpoint_typestyping.List[EndpointType]endpointTypesList<EndpointType>EndpointTypesEndpointType[]EndpointTypes*[]EndpointType= EndpointType.EDGE#Use this property when creating an API.
failOnWarningsbooleanfail_on_warningsboolfailOnWarningsBooleanFailOnWarningsboolFailOnWarnings*bool= false#minCompressionSizeSizemin_compression_sizeSizeminCompressionSizeSizeMinCompressionSizeSizeMinCompressionSizeSize= Compression is disabled.#When compression is enabled, compression or decompression is not applied on the payload if the payload size is smaller than this value. Setting it to zero allows compression for any payload size.
modeRestApiModemodeRestApiModemodeRestApiModeModeRestApiModeModeRestApiMode= `merge` for REST APIs created af…#notes · default
Valid values are overwrite or merge.
For overwrite, the new API definition replaces the existing one. The existing API identifier remains unchanged.
For merge, the new API definition is merged with the existing API.
If you don't specify this property, a default value is chosen:
- For REST APIs created before March 29, 2021, the default is
overwrite - For REST APIs created after March 29, 2021, the new API definition takes precedence, but any container types such as endpoint configurations and binary media types are merged with the existing API.
Use the default mode to define top-level RestApi properties in addition to using OpenAPI. Generally, it's preferred to use API Gateway's OpenAPI extensions to model these properties.
Default: merge for REST APIs created after March 29, 2021, otherwise overwrite
parameters{ [key: string]: string }parameterstyping.Mapping[str, str]parametersMap<String, String>ParametersIDictionary<string, string>Parameters*map[string]*string= No parameters.#policyPolicyDocumentpolicyPolicyDocumentpolicyPolicyDocumentPolicyPolicyDocumentPolicyPolicyDocument= No policy.#restApiNamestringrest_api_namestrrestApiNameStringRestApiNamestringRestApiName*string= ID of the RestApi construct.#retainDeploymentsbooleanretain_deploymentsboolretainDeploymentsBooleanRetainDeploymentsboolRetainDeployments*bool= false#This allows manually reverting stages to point to old deployments via the AWS Console.
Properties
deploymentStageStagedeployment_stageStagedeploymentStageStageDeploymentStageStageDeploymentStageStagerequired#If deploy is disabled, you will need to explicitly assign this value in order to set up integrations.
domainNameDomainNamedomain_nameDomainNamedomainNameDomainNameDomainNameDomainNameDomainNameDomainName#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
latestDeploymentDeploymentlatest_deploymentDeploymentlatestDeploymentDeploymentLatestDeploymentDeploymentLatestDeploymentDeployment#This resource will be automatically updated every time the REST API model changes. This will be undefined if deploy is false.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#Note that this is different from restApiId.
restApiRefRestApiReferencerest_api_refRestApiReferencerestApiRefRestApiReferenceRestApiRefRestApiReferenceRestApiRefRestApiReferencerequired#restApiRootResourceIdstringrest_api_root_resource_idstrrestApiRootResourceIdStringRestApiRootResourceIdstringRestApiRootResourceId*stringrequired#Resources and Methods are added to this resource.
Methods
addApiKey(id: string, options?: ApiKeyOptions): IApiKeydef add_api_key(self, id: str, options: typing.Optional[ApiKeyOptions] = None) -> IApiKeypublic IApiKey addApiKey(String id, ApiKeyOptions options)public IApiKey AddApiKey(string id, ApiKeyOptions? options = null)func AddApiKey(Id *string, Options ApiKeyOptions) IApiKey#addDomainName(id: string, options: DomainNameOptions): DomainNamedef add_domain_name(self, id: str, options: DomainNameOptions) -> DomainNamepublic DomainName addDomainName(String id, DomainNameOptions options)public DomainName AddDomainName(string id, DomainNameOptions options)func AddDomainName(Id *string, Options DomainNameOptions) DomainName#2 parameters
Parameters
ididididId— The construct id.optionsoptionsoptionsoptionsOptions— custom domain options.
addGatewayResponse(id: string, options: GatewayResponseOptions): GatewayResponsedef add_gateway_response(self, id: str, options: GatewayResponseOptions) -> GatewayResponsepublic GatewayResponse addGatewayResponse(String id, GatewayResponseOptions options)public GatewayResponse AddGatewayResponse(string id, GatewayResponseOptions options)func AddGatewayResponse(Id *string, Options GatewayResponseOptions) GatewayResponse#addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResultdef add_to_resource_policy(self, statement: PolicyStatement) -> AddToResourcePolicyResultpublic AddToResourcePolicyResult addToResourcePolicy(PolicyStatement statement)public AddToResourcePolicyResult AddToResourcePolicy(PolicyStatement statement)func AddToResourcePolicy(Statement PolicyStatement) AddToResourcePolicyResult#A resource policy will be automatically created upon the first call to addToResourcePolicy.
Note that this does not work with imported rest api.
1 parameter
Parameters
statementstatementstatementstatementStatement— The policy statement to add.
addUsagePlan(id: string, props?: UsagePlanProps): UsagePlandef add_usage_plan(self, id: str, props: typing.Optional[UsagePlanProps] = None) -> UsagePlanpublic UsagePlan addUsagePlan(String id, UsagePlanProps props)public UsagePlan AddUsagePlan(string id, UsagePlanProps? props = null)func AddUsagePlan(Id *string, Props UsagePlanProps) UsagePlan#applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
arnForExecuteApi(method?: string, path?: string, stage?: string): stringdef arn_for_execute_api(self, method: typing.Optional[str] = None, path: typing.Optional[str] = None, stage: typing.Optional[str] = None) -> strpublic String arnForExecuteApi(String method, String path, String stage)public string ArnForExecuteApi(string? method = null, string? path = null, string? stage = null)func ArnForExecuteApi(Method *string, Path *string, Stage *string) *string#grantInvokeFromVpcEndpointsOnly(vpcEndpoints: IVpcEndpoint[]): voiddef grant_invoke_from_vpc_endpoints_only(self, vpc_endpoints: typing.List[IVpcEndpoint]) -> Nonepublic void grantInvokeFromVpcEndpointsOnly(List<IVpcEndpoint> vpcEndpoints)public void GrantInvokeFromVpcEndpointsOnly(IVpcEndpoint[] vpcEndpoints)func GrantInvokeFromVpcEndpointsOnly(VpcEndpoints *[]IVpcEndpoint)#1 parameter
Parameters
vpcEndpointsvpc_endpointsvpcEndpointsvpcEndpointsVpcEndpoints— the interface VPC endpoints to grant access to.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#metricCacheHitCount(props?: MetricOptions): Metricdef metric_cache_hit_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCacheHitCount(MetricOptions props)public Metric MetricCacheHitCount(MetricOptions? props = null)func MetricCacheHitCount(Props MetricOptions) Metric#Default: sum over 5 minutes
metricCacheMissCount(props?: MetricOptions): Metricdef metric_cache_miss_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCacheMissCount(MetricOptions props)public Metric MetricCacheMissCount(MetricOptions? props = null)func MetricCacheMissCount(Props MetricOptions) Metric#Default: sum over 5 minutes
metricClientError(props?: MetricOptions): Metricdef metric_client_error(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricClientError(MetricOptions props)public Metric MetricClientError(MetricOptions? props = null)func MetricClientError(Props MetricOptions) Metric#Default: sum over 5 minutes
metricCount(props?: MetricOptions): Metricdef metric_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCount(MetricOptions props)public Metric MetricCount(MetricOptions? props = null)func MetricCount(Props MetricOptions) Metric#Default: sample count over 5 minutes
metricIntegrationLatency(props?: MetricOptions): Metricdef metric_integration_latency(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricIntegrationLatency(MetricOptions props)public Metric MetricIntegrationLatency(MetricOptions? props = null)func MetricIntegrationLatency(Props MetricOptions) Metric#Default: average over 5 minutes.
metricLatency(props?: MetricOptions): Metricdef metric_latency(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricLatency(MetricOptions props)public Metric MetricLatency(MetricOptions? props = null)func MetricLatency(Props MetricOptions) Metric#The latency includes the integration latency and other API Gateway overhead.
Default: average over 5 minutes.
metricServerError(props?: MetricOptions): Metricdef metric_server_error(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricServerError(MetricOptions props)public Metric MetricServerError(MetricOptions? props = null)func MetricServerError(Props MetricOptions) Metric#Default: sum over 5 minutes
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#urlForPath(path?: string): stringdef url_for_path(self, path: typing.Optional[str] = None) -> strpublic String urlForPath(String path)public string UrlForPath(string? path = null)func UrlForPath(Path *string) *string#Fails if deploymentStage is not set either by deploy or explicitly.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.