AWS Classic

v4.30.0 published on Tuesday, Nov 30, 2021 by Pulumi

Method

Provides a HTTP Method for an API Gateway Resource.

Usage with Cognito User Pool Authorizer

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const cognitoUserPoolName = config.requireObject("cognitoUserPoolName");
const thisUserPools = aws.cognito.getUserPools({
    name: cognitoUserPoolName,
});
const thisRestApi = new aws.apigateway.RestApi("thisRestApi", {});
const thisResource = new aws.apigateway.Resource("thisResource", {
    restApi: thisRestApi.id,
    parentId: thisRestApi.rootResourceId,
    pathPart: "{proxy+}",
});
const thisAuthorizer = new aws.apigateway.Authorizer("thisAuthorizer", {
    type: "COGNITO_USER_POOLS",
    restApi: thisRestApi.id,
    providerArns: thisUserPools.then(thisUserPools => thisUserPools.arns),
});
const any = new aws.apigateway.Method("any", {
    restApi: thisRestApi.id,
    resourceId: thisResource.id,
    httpMethod: "ANY",
    authorization: "COGNITO_USER_POOLS",
    authorizerId: thisAuthorizer.id,
    requestParameters: {
        "method.request.path.proxy": true,
    },
});
import pulumi
import pulumi_aws as aws

config = pulumi.Config()
cognito_user_pool_name = config.require_object("cognitoUserPoolName")
this_user_pools = aws.cognito.get_user_pools(name=cognito_user_pool_name)
this_rest_api = aws.apigateway.RestApi("thisRestApi")
this_resource = aws.apigateway.Resource("thisResource",
    rest_api=this_rest_api.id,
    parent_id=this_rest_api.root_resource_id,
    path_part="{proxy+}")
this_authorizer = aws.apigateway.Authorizer("thisAuthorizer",
    type="COGNITO_USER_POOLS",
    rest_api=this_rest_api.id,
    provider_arns=this_user_pools.arns)
any = aws.apigateway.Method("any",
    rest_api=this_rest_api.id,
    resource_id=this_resource.id,
    http_method="ANY",
    authorization="COGNITO_USER_POOLS",
    authorizer_id=this_authorizer.id,
    request_parameters={
        "method.request.path.proxy": True,
    })
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var cognitoUserPoolName = config.RequireObject<dynamic>("cognitoUserPoolName");
        var thisUserPools = Output.Create(Aws.Cognito.GetUserPools.InvokeAsync(new Aws.Cognito.GetUserPoolsArgs
        {
            Name = cognitoUserPoolName,
        }));
        var thisRestApi = new Aws.ApiGateway.RestApi("thisRestApi", new Aws.ApiGateway.RestApiArgs
        {
        });
        var thisResource = new Aws.ApiGateway.Resource("thisResource", new Aws.ApiGateway.ResourceArgs
        {
            RestApi = thisRestApi.Id,
            ParentId = thisRestApi.RootResourceId,
            PathPart = "{proxy+}",
        });
        var thisAuthorizer = new Aws.ApiGateway.Authorizer("thisAuthorizer", new Aws.ApiGateway.AuthorizerArgs
        {
            Type = "COGNITO_USER_POOLS",
            RestApi = thisRestApi.Id,
            ProviderArns = thisUserPools.Apply(thisUserPools => thisUserPools.Arns),
        });
        var any = new Aws.ApiGateway.Method("any", new Aws.ApiGateway.MethodArgs
        {
            RestApi = thisRestApi.Id,
            ResourceId = thisResource.Id,
            HttpMethod = "ANY",
            Authorization = "COGNITO_USER_POOLS",
            AuthorizerId = thisAuthorizer.Id,
            RequestParameters = 
            {
                { "method.request.path.proxy", true },
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/apigateway"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cognito"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		cognitoUserPoolName := cfg.RequireObject("cognitoUserPoolName")
		thisUserPools, err := cognito.GetUserPools(ctx, &cognito.GetUserPoolsArgs{
			Name: cognitoUserPoolName,
		}, nil)
		if err != nil {
			return err
		}
		thisRestApi, err := apigateway.NewRestApi(ctx, "thisRestApi", nil)
		if err != nil {
			return err
		}
		thisResource, err := apigateway.NewResource(ctx, "thisResource", &apigateway.ResourceArgs{
			RestApi:  thisRestApi.ID(),
			ParentId: thisRestApi.RootResourceId,
			PathPart: pulumi.String("{proxy+}"),
		})
		if err != nil {
			return err
		}
		thisAuthorizer, err := apigateway.NewAuthorizer(ctx, "thisAuthorizer", &apigateway.AuthorizerArgs{
			Type:         pulumi.String("COGNITO_USER_POOLS"),
			RestApi:      thisRestApi.ID(),
			ProviderArns: interface{}(thisUserPools.Arns),
		})
		if err != nil {
			return err
		}
		_, err = apigateway.NewMethod(ctx, "any", &apigateway.MethodArgs{
			RestApi:       thisRestApi.ID(),
			ResourceId:    thisResource.ID(),
			HttpMethod:    pulumi.String("ANY"),
			Authorization: pulumi.String("COGNITO_USER_POOLS"),
			AuthorizerId:  thisAuthorizer.ID(),
			RequestParameters: pulumi.BoolMap{
				"method.request.path.proxy": pulumi.Bool(true),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var myDemoAPI = new Aws.ApiGateway.RestApi("myDemoAPI", new Aws.ApiGateway.RestApiArgs
        {
            Description = "This is my API for demonstration purposes",
        });
        var myDemoResource = new Aws.ApiGateway.Resource("myDemoResource", new Aws.ApiGateway.ResourceArgs
        {
            RestApi = myDemoAPI.Id,
            ParentId = myDemoAPI.RootResourceId,
            PathPart = "mydemoresource",
        });
        var myDemoMethod = new Aws.ApiGateway.Method("myDemoMethod", new Aws.ApiGateway.MethodArgs
        {
            RestApi = myDemoAPI.Id,
            ResourceId = myDemoResource.Id,
            HttpMethod = "GET",
            Authorization = "NONE",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/apigateway"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		myDemoAPI, err := apigateway.NewRestApi(ctx, "myDemoAPI", &apigateway.RestApiArgs{
			Description: pulumi.String("This is my API for demonstration purposes"),
		})
		if err != nil {
			return err
		}
		myDemoResource, err := apigateway.NewResource(ctx, "myDemoResource", &apigateway.ResourceArgs{
			RestApi:  myDemoAPI.ID(),
			ParentId: myDemoAPI.RootResourceId,
			PathPart: pulumi.String("mydemoresource"),
		})
		if err != nil {
			return err
		}
		_, err = apigateway.NewMethod(ctx, "myDemoMethod", &apigateway.MethodArgs{
			RestApi:       myDemoAPI.ID(),
			ResourceId:    myDemoResource.ID(),
			HttpMethod:    pulumi.String("GET"),
			Authorization: pulumi.String("NONE"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

my_demo_api = aws.apigateway.RestApi("myDemoAPI", description="This is my API for demonstration purposes")
my_demo_resource = aws.apigateway.Resource("myDemoResource",
    rest_api=my_demo_api.id,
    parent_id=my_demo_api.root_resource_id,
    path_part="mydemoresource")
my_demo_method = aws.apigateway.Method("myDemoMethod",
    rest_api=my_demo_api.id,
    resource_id=my_demo_resource.id,
    http_method="GET",
    authorization="NONE")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const myDemoAPI = new aws.apigateway.RestApi("myDemoAPI", {description: "This is my API for demonstration purposes"});
const myDemoResource = new aws.apigateway.Resource("myDemoResource", {
    restApi: myDemoAPI.id,
    parentId: myDemoAPI.rootResourceId,
    pathPart: "mydemoresource",
});
const myDemoMethod = new aws.apigateway.Method("myDemoMethod", {
    restApi: myDemoAPI.id,
    resourceId: myDemoResource.id,
    httpMethod: "GET",
    authorization: "NONE",
});

Create a Method Resource

new Method(name: string, args: MethodArgs, opts?: CustomResourceOptions);
@overload
def Method(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           api_key_required: Optional[bool] = None,
           authorization: Optional[str] = None,
           authorization_scopes: Optional[Sequence[str]] = None,
           authorizer_id: Optional[str] = None,
           http_method: Optional[str] = None,
           operation_name: Optional[str] = None,
           request_models: Optional[Mapping[str, str]] = None,
           request_parameters: Optional[Mapping[str, bool]] = None,
           request_validator_id: Optional[str] = None,
           resource_id: Optional[str] = None,
           rest_api: Optional[str] = None)
@overload
def Method(resource_name: str,
           args: MethodArgs,
           opts: Optional[ResourceOptions] = None)
func NewMethod(ctx *Context, name string, args MethodArgs, opts ...ResourceOption) (*Method, error)
public Method(string name, MethodArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args MethodArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args MethodArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args MethodArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args MethodArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

Method Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The Method resource accepts the following input properties:

Authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
HttpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
ResourceId string
The API resource ID
RestApi string | string
The ID of the associated REST API
ApiKeyRequired bool
Specify if the method requires an API key
AuthorizationScopes List<string>
The authorization scopes used when the authorization is COGNITO_USER_POOLS
AuthorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
OperationName string
The 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 Dictionary<string, string>
A 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 aws.apigateway.Model’s name.
RequestParameters Dictionary<string, bool>
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
RequestValidatorId string
The ID of a aws.apigateway.RequestValidator
Authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
HttpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
ResourceId string
The API resource ID
RestApi string | string
The ID of the associated REST API
ApiKeyRequired bool
Specify if the method requires an API key
AuthorizationScopes []string
The authorization scopes used when the authorization is COGNITO_USER_POOLS
AuthorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
OperationName string
The 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 map[string]string
A 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 aws.apigateway.Model’s name.
RequestParameters map[string]bool
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
RequestValidatorId string
The ID of a aws.apigateway.RequestValidator
authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
httpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
resourceId string
The API resource ID
restApi string | RestApi
The ID of the associated REST API
apiKeyRequired boolean
Specify if the method requires an API key
authorizationScopes string[]
The authorization scopes used when the authorization is COGNITO_USER_POOLS
authorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
operationName string
The 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 {[key: string]: string}
A 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 aws.apigateway.Model’s name.
requestParameters {[key: string]: boolean}
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
requestValidatorId string
The ID of a aws.apigateway.RequestValidator
authorization str
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
http_method str
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
resource_id str
The API resource ID
rest_api str | str
The ID of the associated REST API
api_key_required bool
Specify if the method requires an API key
authorization_scopes Sequence[str]
The authorization scopes used when the authorization is COGNITO_USER_POOLS
authorizer_id str
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
operation_name str
The 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.
request_models Mapping[str, str]
A 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 aws.apigateway.Model’s name.
request_parameters Mapping[str, bool]
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
request_validator_id str
The ID of a aws.apigateway.RequestValidator

Outputs

All input properties are implicitly available as output properties. Additionally, the Method resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing Method Resource

Get an existing Method resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: MethodState, opts?: CustomResourceOptions): Method
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        api_key_required: Optional[bool] = None,
        authorization: Optional[str] = None,
        authorization_scopes: Optional[Sequence[str]] = None,
        authorizer_id: Optional[str] = None,
        http_method: Optional[str] = None,
        operation_name: Optional[str] = None,
        request_models: Optional[Mapping[str, str]] = None,
        request_parameters: Optional[Mapping[str, bool]] = None,
        request_validator_id: Optional[str] = None,
        resource_id: Optional[str] = None,
        rest_api: Optional[str] = None) -> Method
func GetMethod(ctx *Context, name string, id IDInput, state *MethodState, opts ...ResourceOption) (*Method, error)
public static Method Get(string name, Input<string> id, MethodState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

ApiKeyRequired bool
Specify if the method requires an API key
Authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
AuthorizationScopes List<string>
The authorization scopes used when the authorization is COGNITO_USER_POOLS
AuthorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
HttpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
OperationName string
The 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 Dictionary<string, string>
A 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 aws.apigateway.Model’s name.
RequestParameters Dictionary<string, bool>
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
RequestValidatorId string
The ID of a aws.apigateway.RequestValidator
ResourceId string
The API resource ID
RestApi string | string
The ID of the associated REST API
ApiKeyRequired bool
Specify if the method requires an API key
Authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
AuthorizationScopes []string
The authorization scopes used when the authorization is COGNITO_USER_POOLS
AuthorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
HttpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
OperationName string
The 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 map[string]string
A 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 aws.apigateway.Model’s name.
RequestParameters map[string]bool
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
RequestValidatorId string
The ID of a aws.apigateway.RequestValidator
ResourceId string
The API resource ID
RestApi string | string
The ID of the associated REST API
apiKeyRequired boolean
Specify if the method requires an API key
authorization string
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
authorizationScopes string[]
The authorization scopes used when the authorization is COGNITO_USER_POOLS
authorizerId string
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
httpMethod string
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
operationName string
The 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 {[key: string]: string}
A 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 aws.apigateway.Model’s name.
requestParameters {[key: string]: boolean}
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
requestValidatorId string
The ID of a aws.apigateway.RequestValidator
resourceId string
The API resource ID
restApi string | RestApi
The ID of the associated REST API
api_key_required bool
Specify if the method requires an API key
authorization str
The type of authorization used for the method (NONE, CUSTOM, AWS_IAM, COGNITO_USER_POOLS)
authorization_scopes Sequence[str]
The authorization scopes used when the authorization is COGNITO_USER_POOLS
authorizer_id str
The authorizer id to be used when the authorization is CUSTOM or COGNITO_USER_POOLS
http_method str
The HTTP Method (GET, POST, PUT, DELETE, HEAD, OPTIONS, ANY)
operation_name str
The 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.
request_models Mapping[str, str]
A 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 aws.apigateway.Model’s name.
request_parameters Mapping[str, bool]
A 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: request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true} would define that the header X-Some-Header and the query string some-query-param must be provided in the request.
request_validator_id str
The ID of a aws.apigateway.RequestValidator
resource_id str
The API resource ID
rest_api str | str
The ID of the associated REST API

Import

aws_api_gateway_method can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD, e.g.,

 $ pulumi import aws:apigateway/method:Method example 12345abcde/67890fghij/GET

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.