Skip to content

Resource: awsApiGatewayMethod

Provides a HTTP Method for an API Gateway Resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsApiGatewayRestApiMyDemoApi =
  new aws.apiGatewayRestApi.ApiGatewayRestApi(this, "MyDemoAPI", {
    description: "This is my API for demonstration purposes",
    name: "MyDemoAPI",
  });
const awsApiGatewayResourceMyDemoResource =
  new aws.apiGatewayResource.ApiGatewayResource(this, "MyDemoResource", {
    parentId: awsApiGatewayRestApiMyDemoApi.rootResourceId,
    pathPart: "mydemoresource",
    restApiId: awsApiGatewayRestApiMyDemoApi.id,
  });
new aws.apiGatewayMethod.ApiGatewayMethod(this, "MyDemoMethod", {
  authorization: "NONE",
  httpMethod: "GET",
  resourceId: awsApiGatewayResourceMyDemoResource.id,
  restApiId: awsApiGatewayRestApiMyDemoApi.id,
});

Usage with Cognito User Pool Authorizer

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
You can read more about this at https://cdk.tf/variables*/
const cognitoUserPoolName = new cdktf.TerraformVariable(
  this,
  "cognito_user_pool_name",
  {}
);
const awsApiGatewayRestApiThis = new aws.apiGatewayRestApi.ApiGatewayRestApi(
  this,
  "this",
  {
    name: "with-authorizer",
  }
);
const dataAwsCognitoUserPoolsThis =
  new aws.dataAwsCognitoUserPools.DataAwsCognitoUserPools(this, "this_2", {
    name: cognitoUserPoolName.value,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAwsCognitoUserPoolsThis.overrideLogicalId("this");
const awsApiGatewayAuthorizerThis =
  new aws.apiGatewayAuthorizer.ApiGatewayAuthorizer(this, "this_3", {
    name: "CognitoUserPoolAuthorizer",
    providerArns: dataAwsCognitoUserPoolsThis.arns,
    restApiId: awsApiGatewayRestApiThis.id,
    type: "COGNITO_USER_POOLS",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayAuthorizerThis.overrideLogicalId("this");
const awsApiGatewayResourceThis = new aws.apiGatewayResource.ApiGatewayResource(
  this,
  "this_4",
  {
    parentId: awsApiGatewayRestApiThis.rootResourceId,
    pathPart: "{proxy+}",
    restApiId: awsApiGatewayRestApiThis.id,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayResourceThis.overrideLogicalId("this");
new aws.apiGatewayMethod.ApiGatewayMethod(this, "any", {
  authorization: "COGNITO_USER_POOLS",
  authorizerId: awsApiGatewayAuthorizerThis.id,
  httpMethod: "ANY",
  requestParameters: {
    "method.request.path.proxy": true,
  },
  resourceId: awsApiGatewayResourceThis.id,
  restApiId: awsApiGatewayRestApiThis.id,
});

Argument Reference

The following arguments are supported:

  • restApiId - (Required) ID of the associated REST API
  • resourceId - (Required) API resource ID
  • httpMethod - (Required) HTTP Method (get, post, put, delete, head, options, any)
  • authorization - (Required) Type of authorization used for the method (none, custom, AWS_IAM, COGNITO_USER_POOLS)
  • authorizerId - (Optional) Authorizer id to be used when the authorization is custom or COGNITO_USER_POOLS
  • authorizationScopes - (Optional) Authorization scopes used when the authorization is COGNITO_USER_POOLS
  • apiKeyRequired - (Optional) Specify if the method requires an API key
  • operationName - (Optional) Function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
  • requestModels - (Optional) Map of the API models used for the request's content type where key is the content type (e.g., application/json) and value is either error, empty (built-in models) or awsApiGatewayModel's name.
  • requestValidatorId - (Optional) ID of a awsApiGatewayRequestValidator
  • requestParameters - (Optional) Map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (true) or optional (false). For example: requestParameters = {"methodRequestHeaderXSomeHeader" =True "methodRequestQuerystringSomeQueryParam" =True} would define that the header xSomeHeader and the query string someQueryParam must be provided in the request.

Attributes Reference

No additional attributes are exported.

Import

awsApiGatewayMethod can be imported using restApiId/resourceId/httpMethod, e.g.,

$ terraform import aws_api_gateway_method.example 12345abcde/67890fghij/GET