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.require("cognitoUserPoolName");
const thisUserPools = pulumi.output(aws.cognito.getUserPools({
name: cognitoUserPoolName,
}, { async: true }));
const thisRestApi = new aws.apigateway.RestApi("this", {});
const thisResource = new aws.apigateway.Resource("this", {
parentId: thisRestApi.rootResourceId,
pathPart: "{proxy+}",
restApi: thisRestApi.id,
});
const thisAuthorizer = new aws.apigateway.Authorizer("this", {
providerArns: thisUserPools.arns,
restApi: thisRestApi.id,
type: "COGNITO_USER_POOLS",
});
const any = new aws.apigateway.Method("any", {
authorization: "COGNITO_USER_POOLS",
authorizerId: thisAuthorizer.id,
httpMethod: "ANY",
requestParameters: {
"method.request.path.proxy": true,
},
resourceId: thisResource.id,
restApi: thisRestApi.id,
});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",
parent_id=this_rest_api.root_resource_id,
path_part="{proxy+}",
rest_api=this_rest_api.id)
this_authorizer = aws.apigateway.Authorizer("thisAuthorizer",
provider_arns=this_user_pools.arns,
rest_api=this_rest_api.id,
type="COGNITO_USER_POOLS")
any = aws.apigateway.Method("any",
authorization="COGNITO_USER_POOLS",
authorizer_id=this_authorizer.id,
http_method="ANY",
request_parameters={
"method.request.path.proxy": True,
},
resource_id=this_resource.id,
rest_api=this_rest_api.id)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
{
ParentId = thisRestApi.RootResourceId,
PathPart = "{proxy+}",
RestApi = thisRestApi.Id,
});
var thisAuthorizer = new Aws.ApiGateway.Authorizer("thisAuthorizer", new Aws.ApiGateway.AuthorizerArgs
{
ProviderArns = thisUserPools.Apply(thisUserPools => thisUserPools.Arns),
RestApi = thisRestApi.Id,
Type = "COGNITO_USER_POOLS",
});
var any = new Aws.ApiGateway.Method("any", new Aws.ApiGateway.MethodArgs
{
Authorization = "COGNITO_USER_POOLS",
AuthorizerId = thisAuthorizer.Id,
HttpMethod = "ANY",
RequestParameters =
{
{ "method.request.path.proxy", true },
},
ResourceId = thisResource.Id,
RestApi = thisRestApi.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/cognito"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
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{
ParentId: thisRestApi.RootResourceId,
PathPart: pulumi.String("{proxy+}"),
RestApi: thisRestApi.ID(),
})
if err != nil {
return err
}
thisAuthorizer, err := apigateway.NewAuthorizer(ctx, "thisAuthorizer", &apigateway.AuthorizerArgs{
ProviderArns: toPulumiStringArray(thisUserPools.Arns),
RestApi: thisRestApi.ID(),
Type: pulumi.String("COGNITO_USER_POOLS"),
})
if err != nil {
return err
}
_, err = apigateway.NewMethod(ctx, "any", &apigateway.MethodArgs{
Authorization: pulumi.String("COGNITO_USER_POOLS"),
AuthorizerId: thisAuthorizer.ID(),
HttpMethod: pulumi.String("ANY"),
RequestParameters: pulumi.BoolMap{
"method.request.path.proxy": pulumi.Bool(true),
},
ResourceId: thisResource.ID(),
RestApi: thisRestApi.ID(),
})
if err != nil {
return err
}
return nil
})
}
func toPulumiStringArray(arr []string) pulumi.StringArray {
var pulumiArr pulumi.StringArray
for _, v := range arr {
pulumiArr = append(pulumiArr, pulumi.String(v))
}
return pulumiArr
}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
{
ParentId = myDemoAPI.RootResourceId,
PathPart = "mydemoresource",
RestApi = myDemoAPI.Id,
});
var myDemoMethod = new Aws.ApiGateway.Method("myDemoMethod", new Aws.ApiGateway.MethodArgs
{
Authorization = "NONE",
HttpMethod = "GET",
ResourceId = myDemoResource.Id,
RestApi = myDemoAPI.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway"
"github.com/pulumi/pulumi/sdk/v2/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{
ParentId: myDemoAPI.RootResourceId,
PathPart: pulumi.String("mydemoresource"),
RestApi: myDemoAPI.ID(),
})
if err != nil {
return err
}
_, err = apigateway.NewMethod(ctx, "myDemoMethod", &apigateway.MethodArgs{
Authorization: pulumi.String("NONE"),
HttpMethod: pulumi.String("GET"),
ResourceId: myDemoResource.ID(),
RestApi: myDemoAPI.ID(),
})
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",
parent_id=my_demo_api.root_resource_id,
path_part="mydemoresource",
rest_api=my_demo_api.id)
my_demo_method = aws.apigateway.Method("myDemoMethod",
authorization="NONE",
http_method="GET",
resource_id=my_demo_resource.id,
rest_api=my_demo_api.id)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", {
parentId: myDemoAPI.rootResourceId,
pathPart: "mydemoresource",
restApi: myDemoAPI.id,
});
const myDemoMethod = new aws.apigateway.Method("MyDemoMethod", {
authorization: "NONE",
httpMethod: "GET",
resourceId: myDemoResource.id,
restApi: myDemoAPI.id,
});Create a Method Resource
new Method(name: string, args: MethodArgs, opts?: CustomResourceOptions);def Method(resource_name, opts=None, api_key_required=None, authorization=None, authorization_scopes=None, authorizer_id=None, http_method=None, request_models=None, request_parameters=None, request_validator_id=None, resource_id=None, rest_api=None, __props__=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.
- opts ResourceOptions
- A bag of options that control this 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 Programming Model docs.
Inputs
The Method resource accepts the following input properties:
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- Http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- Resource
Id string The API resource ID
- Rest
Api string The ID of the associated REST API
- Api
Key boolRequired Specify if the method requires an API key
- List<string>
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- Request
Models 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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- Request
Parameters 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- Request
Validator stringId The ID of a
aws.apigateway.RequestValidator
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- Http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- Resource
Id string The API resource ID
- Rest
Api interface{} The ID of the associated REST API
- Api
Key boolRequired Specify if the method requires an API key
- []string
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- Request
Models 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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- Request
Parameters 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- Request
Validator stringId The ID of a
aws.apigateway.RequestValidator
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- resource
Id string The API resource ID
- rest
Api string | RestApi The ID of the associated REST API
- api
Key booleanRequired Specify if the method requires an API key
- string[]
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- request
Models {[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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- request
Parameters {[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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- request
Validator stringId The ID of a
aws.apigateway.RequestValidator
- 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 string | str The ID of the associated REST API
- api_
key_ boolrequired Specify if the method requires an API key
- List[str]
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- str
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- request_
models Dict[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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- request_
parameters Dict[str, 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- request_
validator_ strid 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:
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): Methodstatic get(resource_name, id, opts=None, api_key_required=None, authorization=None, authorization_scopes=None, authorizer_id=None, http_method=None, request_models=None, request_parameters=None, request_validator_id=None, resource_id=None, rest_api=None, __props__=None);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:
- Api
Key boolRequired Specify if the method requires an API key
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- List<string>
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- Http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- Request
Models 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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- Request
Parameters 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- Request
Validator stringId The ID of a
aws.apigateway.RequestValidator- Resource
Id string The API resource ID
- Rest
Api string The ID of the associated REST API
- Api
Key boolRequired Specify if the method requires an API key
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- []string
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- Http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- Request
Models 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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- Request
Parameters 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- Request
Validator stringId The ID of a
aws.apigateway.RequestValidator- Resource
Id string The API resource ID
- Rest
Api interface{} The ID of the associated REST API
- api
Key booleanRequired Specify if the method requires an API key
- string
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- string[]
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- string
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- http
Method string The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- request
Models {[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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- request
Parameters {[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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- request
Validator stringId The ID of a
aws.apigateway.RequestValidator- resource
Id string The API resource ID
- rest
Api string | RestApi The ID of the associated REST API
- api_
key_ boolrequired Specify if the method requires an API key
- str
The type of authorization used for the method (
NONE,CUSTOM,AWS_IAM,COGNITO_USER_POOLS)- List[str]
The authorization scopes used when the authorization is
COGNITO_USER_POOLS- str
The authorizer id to be used when the authorization is
CUSTOMorCOGNITO_USER_POOLS- http_
method str The HTTP Method (
GET,POST,PUT,DELETE,HEAD,OPTIONS,ANY)- request_
models Dict[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 eitherError,Empty(built-in models) oraws.apigateway.Model’sname.- request_
parameters Dict[str, 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 headerX-Some-Headerand the query stringsome-query-parammust be provided in the request.- request_
validator_ strid The ID of a
aws.apigateway.RequestValidator- resource_
id str The API resource ID
- rest_
api string | str The ID of the associated REST API
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.