Welcome to Pulumi Registry, your window into the cloud. Read the announcement.

AWS Classic

v4.25.0 published on Friday, Oct 15, 2021 by Pulumi

UsagePlan

Provides an API Gateway Usage Plan.

Example Usage

using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
	private static string ComputeSHA1(string input) {
		return BitConverter.ToString(
			SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(input))
		).Replace("-","").ToLowerInvariant());
	}

    public MyStack()
    {
        var exampleRestApi = new Aws.ApiGateway.RestApi("exampleRestApi", new Aws.ApiGateway.RestApiArgs
        {
            Body = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                { "openapi", "3.0.1" },
                { "info", new Dictionary<string, object?>
                {
                    { "title", "example" },
                    { "version", "1.0" },
                } },
                { "paths", new Dictionary<string, object?>
                {
                    { "/path1", new Dictionary<string, object?>
                    {
                        { "get", new Dictionary<string, object?>
                        {
                            { "x-amazon-apigateway-integration", new Dictionary<string, object?>
                            {
                                { "httpMethod", "GET" },
                                { "payloadFormatVersion", "1.0" },
                                { "type", "HTTP_PROXY" },
                                { "uri", "https://ip-ranges.amazonaws.com/ip-ranges.json" },
                            } },
                        } },
                    } },
                } },
            }),
        });
        var exampleDeployment = new Aws.ApiGateway.Deployment("exampleDeployment", new Aws.ApiGateway.DeploymentArgs
        {
            RestApi = exampleRestApi.Id,
            Triggers = 
            {
                { "redeployment", exampleRestApi.Body.Apply(body => JsonSerializer.Serialize(body)).Apply(toJSON => ComputeSHA1(toJSON)) },
            },
        });
        var development = new Aws.ApiGateway.Stage("development", new Aws.ApiGateway.StageArgs
        {
            Deployment = exampleDeployment.Id,
            RestApi = exampleRestApi.Id,
            StageName = "development",
        });
        var production = new Aws.ApiGateway.Stage("production", new Aws.ApiGateway.StageArgs
        {
            Deployment = exampleDeployment.Id,
            RestApi = exampleRestApi.Id,
            StageName = "production",
        });
        var exampleUsagePlan = new Aws.ApiGateway.UsagePlan("exampleUsagePlan", new Aws.ApiGateway.UsagePlanArgs
        {
            Description = "my description",
            ProductCode = "MYCODE",
            ApiStages = 
            {
                new Aws.ApiGateway.Inputs.UsagePlanApiStageArgs
                {
                    ApiId = exampleRestApi.Id,
                    Stage = development.StageName,
                },
                new Aws.ApiGateway.Inputs.UsagePlanApiStageArgs
                {
                    ApiId = exampleRestApi.Id,
                    Stage = production.StageName,
                },
            },
            QuotaSettings = new Aws.ApiGateway.Inputs.UsagePlanQuotaSettingsArgs
            {
                Limit = 20,
                Offset = 2,
                Period = "WEEK",
            },
            ThrottleSettings = new Aws.ApiGateway.Inputs.UsagePlanThrottleSettingsArgs
            {
                BurstLimit = 5,
                RateLimit = 10,
            },
        });
    }

}
package main

import (
	"crypto/sha1"
	"encoding/json"
	"fmt"

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

func sha1Hash(input string) string {
	hash := sha1.Sum([]byte(input))
	return hex.EncodeToString(hash[:])
}

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		tmpJSON0, err := json.Marshal(map[string]interface{}{
			"openapi": "3.0.1",
			"info": map[string]interface{}{
				"title":   "example",
				"version": "1.0",
			},
			"paths": map[string]interface{}{
				"/path1": map[string]interface{}{
					"get": map[string]interface{}{
						"x-amazon-apigateway-integration": map[string]interface{}{
							"httpMethod":           "GET",
							"payloadFormatVersion": "1.0",
							"type":                 "HTTP_PROXY",
							"uri":                  "https://ip-ranges.amazonaws.com/ip-ranges.json",
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		exampleRestApi, err := apigateway.NewRestApi(ctx, "exampleRestApi", &apigateway.RestApiArgs{
			Body: pulumi.String(json0),
		})
		if err != nil {
			return err
		}
		exampleDeployment, err := apigateway.NewDeployment(ctx, "exampleDeployment", &apigateway.DeploymentArgs{
			RestApi: exampleRestApi.ID(),
			Triggers: pulumi.StringMap{
				"redeployment": exampleRestApi.Body.ApplyT(func(body string) (pulumi.String, error) {
					var _zero pulumi.String
					tmpJSON1, err := json.Marshal(body)
					if err != nil {
						return _zero, err
					}
					json1 := string(tmpJSON1)
					return json1, nil
				}).(pulumi.StringOutput).ApplyT(func(toJSON string) (pulumi.String, error) {
					return sha1Hash(toJSON), nil
				}).(pulumi.StringOutput),
			},
		})
		if err != nil {
			return err
		}
		development, err := apigateway.NewStage(ctx, "development", &apigateway.StageArgs{
			Deployment: exampleDeployment.ID(),
			RestApi:    exampleRestApi.ID(),
			StageName:  pulumi.String("development"),
		})
		if err != nil {
			return err
		}
		production, err := apigateway.NewStage(ctx, "production", &apigateway.StageArgs{
			Deployment: exampleDeployment.ID(),
			RestApi:    exampleRestApi.ID(),
			StageName:  pulumi.String("production"),
		})
		if err != nil {
			return err
		}
		_, err = apigateway.NewUsagePlan(ctx, "exampleUsagePlan", &apigateway.UsagePlanArgs{
			Description: pulumi.String("my description"),
			ProductCode: pulumi.String("MYCODE"),
			ApiStages: apigateway.UsagePlanApiStageArray{
				&apigateway.UsagePlanApiStageArgs{
					ApiId: exampleRestApi.ID(),
					Stage: development.StageName,
				},
				&apigateway.UsagePlanApiStageArgs{
					ApiId: exampleRestApi.ID(),
					Stage: production.StageName,
				},
			},
			QuotaSettings: &apigateway.UsagePlanQuotaSettingsArgs{
				Limit:  pulumi.Int(20),
				Offset: pulumi.Int(2),
				Period: pulumi.String("WEEK"),
			},
			ThrottleSettings: &apigateway.UsagePlanThrottleSettingsArgs{
				BurstLimit: pulumi.Int(5),
				RateLimit:  pulumi.Float64(10),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import hashlib
import json
import pulumi_aws as aws

example_rest_api = aws.apigateway.RestApi("exampleRestApi", body=json.dumps({
    "openapi": "3.0.1",
    "info": {
        "title": "example",
        "version": "1.0",
    },
    "paths": {
        "/path1": {
            "get": {
                "x-amazon-apigateway-integration": {
                    "httpMethod": "GET",
                    "payloadFormatVersion": "1.0",
                    "type": "HTTP_PROXY",
                    "uri": "https://ip-ranges.amazonaws.com/ip-ranges.json",
                },
            },
        },
    },
}))
example_deployment = aws.apigateway.Deployment("exampleDeployment",
    rest_api=example_rest_api.id,
    triggers={
        "redeployment": example_rest_api.body.apply(lambda body: json.dumps(body)).apply(lambda to_json: hashlib.sha1(to_json.encode()).hexdigest()),
    })
development = aws.apigateway.Stage("development",
    deployment=example_deployment.id,
    rest_api=example_rest_api.id,
    stage_name="development")
production = aws.apigateway.Stage("production",
    deployment=example_deployment.id,
    rest_api=example_rest_api.id,
    stage_name="production")
example_usage_plan = aws.apigateway.UsagePlan("exampleUsagePlan",
    description="my description",
    product_code="MYCODE",
    api_stages=[
        aws.apigateway.UsagePlanApiStageArgs(
            api_id=example_rest_api.id,
            stage=development.stage_name,
        ),
        aws.apigateway.UsagePlanApiStageArgs(
            api_id=example_rest_api.id,
            stage=production.stage_name,
        ),
    ],
    quota_settings=aws.apigateway.UsagePlanQuotaSettingsArgs(
        limit=20,
        offset=2,
        period="WEEK",
    ),
    throttle_settings=aws.apigateway.UsagePlanThrottleSettingsArgs(
        burst_limit=5,
        rate_limit=10,
    ))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as crypto from "crypto";

const exampleRestApi = new aws.apigateway.RestApi("exampleRestApi", {body: JSON.stringify({
    openapi: "3.0.1",
    info: {
        title: "example",
        version: "1.0",
    },
    paths: {
        "/path1": {
            get: {
                "x-amazon-apigateway-integration": {
                    httpMethod: "GET",
                    payloadFormatVersion: "1.0",
                    type: "HTTP_PROXY",
                    uri: "https://ip-ranges.amazonaws.com/ip-ranges.json",
                },
            },
        },
    },
})});
const exampleDeployment = new aws.apigateway.Deployment("exampleDeployment", {
    restApi: exampleRestApi.id,
    triggers: {
        redeployment: exampleRestApi.body.apply(body => JSON.stringify(body)).apply(toJSON => crypto.createHash('sha1').update(toJSON).digest('hex')),
    },
});
const development = new aws.apigateway.Stage("development", {
    deployment: exampleDeployment.id,
    restApi: exampleRestApi.id,
    stageName: "development",
});
const production = new aws.apigateway.Stage("production", {
    deployment: exampleDeployment.id,
    restApi: exampleRestApi.id,
    stageName: "production",
});
const exampleUsagePlan = new aws.apigateway.UsagePlan("exampleUsagePlan", {
    description: "my description",
    productCode: "MYCODE",
    apiStages: [
        {
            apiId: exampleRestApi.id,
            stage: development.stageName,
        },
        {
            apiId: exampleRestApi.id,
            stage: production.stageName,
        },
    ],
    quotaSettings: {
        limit: 20,
        offset: 2,
        period: "WEEK",
    },
    throttleSettings: {
        burstLimit: 5,
        rateLimit: 10,
    },
});

Create a UsagePlan Resource

new UsagePlan(name: string, args?: UsagePlanArgs, opts?: CustomResourceOptions);
@overload
def UsagePlan(resource_name: str,
              opts: Optional[ResourceOptions] = None,
              api_stages: Optional[Sequence[UsagePlanApiStageArgs]] = None,
              description: Optional[str] = None,
              name: Optional[str] = None,
              product_code: Optional[str] = None,
              quota_settings: Optional[UsagePlanQuotaSettingsArgs] = None,
              tags: Optional[Mapping[str, str]] = None,
              throttle_settings: Optional[UsagePlanThrottleSettingsArgs] = None)
@overload
def UsagePlan(resource_name: str,
              args: Optional[UsagePlanArgs] = None,
              opts: Optional[ResourceOptions] = None)
func NewUsagePlan(ctx *Context, name string, args *UsagePlanArgs, opts ...ResourceOption) (*UsagePlan, error)
public UsagePlan(string name, UsagePlanArgs? args = null, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args UsagePlanArgs
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 UsagePlanArgs
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 UsagePlanArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args UsagePlanArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

UsagePlan 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 UsagePlan resource accepts the following input properties:

ApiStages List<UsagePlanApiStageArgs>
The associated API stages of the usage plan.
Description string
The description of a usage plan.
Name string
The name of the usage plan.
ProductCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
QuotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
Tags Dictionary<string, string>
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
ThrottleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
ApiStages []UsagePlanApiStageArgs
The associated API stages of the usage plan.
Description string
The description of a usage plan.
Name string
The name of the usage plan.
ProductCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
QuotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
Tags map[string]string
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
ThrottleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
apiStages UsagePlanApiStageArgs[]
The associated API stages of the usage plan.
description string
The description of a usage plan.
name string
The name of the usage plan.
productCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
quotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
tags {[key: string]: string}
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
throttleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
api_stages Sequence[UsagePlanApiStageArgs]
The associated API stages of the usage plan.
description str
The description of a usage plan.
name str
The name of the usage plan.
product_code str
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
quota_settings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
tags Mapping[str, str]
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
throttle_settings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.

Outputs

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

Arn string
Amazon Resource Name (ARN)
Id string
The provider-assigned unique ID for this managed resource.
TagsAll Dictionary<string, string>
A map of tags assigned to the resource, including those inherited from the provider .
Arn string
Amazon Resource Name (ARN)
Id string
The provider-assigned unique ID for this managed resource.
TagsAll map[string]string
A map of tags assigned to the resource, including those inherited from the provider .
arn string
Amazon Resource Name (ARN)
id string
The provider-assigned unique ID for this managed resource.
tagsAll {[key: string]: string}
A map of tags assigned to the resource, including those inherited from the provider .
arn str
Amazon Resource Name (ARN)
id str
The provider-assigned unique ID for this managed resource.
tags_all Mapping[str, str]
A map of tags assigned to the resource, including those inherited from the provider .

Look up an Existing UsagePlan Resource

Get an existing UsagePlan 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?: UsagePlanState, opts?: CustomResourceOptions): UsagePlan
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        api_stages: Optional[Sequence[UsagePlanApiStageArgs]] = None,
        arn: Optional[str] = None,
        description: Optional[str] = None,
        name: Optional[str] = None,
        product_code: Optional[str] = None,
        quota_settings: Optional[UsagePlanQuotaSettingsArgs] = None,
        tags: Optional[Mapping[str, str]] = None,
        tags_all: Optional[Mapping[str, str]] = None,
        throttle_settings: Optional[UsagePlanThrottleSettingsArgs] = None) -> UsagePlan
func GetUsagePlan(ctx *Context, name string, id IDInput, state *UsagePlanState, opts ...ResourceOption) (*UsagePlan, error)
public static UsagePlan Get(string name, Input<string> id, UsagePlanState? 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:

ApiStages List<UsagePlanApiStageArgs>
The associated API stages of the usage plan.
Arn string
Amazon Resource Name (ARN)
Description string
The description of a usage plan.
Name string
The name of the usage plan.
ProductCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
QuotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
Tags Dictionary<string, string>
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
TagsAll Dictionary<string, string>
A map of tags assigned to the resource, including those inherited from the provider .
ThrottleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
ApiStages []UsagePlanApiStageArgs
The associated API stages of the usage plan.
Arn string
Amazon Resource Name (ARN)
Description string
The description of a usage plan.
Name string
The name of the usage plan.
ProductCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
QuotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
Tags map[string]string
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
TagsAll map[string]string
A map of tags assigned to the resource, including those inherited from the provider .
ThrottleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
apiStages UsagePlanApiStageArgs[]
The associated API stages of the usage plan.
arn string
Amazon Resource Name (ARN)
description string
The description of a usage plan.
name string
The name of the usage plan.
productCode string
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
quotaSettings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
tags {[key: string]: string}
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
tagsAll {[key: string]: string}
A map of tags assigned to the resource, including those inherited from the provider .
throttleSettings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.
api_stages Sequence[UsagePlanApiStageArgs]
The associated API stages of the usage plan.
arn str
Amazon Resource Name (ARN)
description str
The description of a usage plan.
name str
The name of the usage plan.
product_code str
The AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
quota_settings UsagePlanQuotaSettingsArgs
The quota settings of the usage plan.
tags Mapping[str, str]
Key-value map of resource tags. .If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
tags_all Mapping[str, str]
A map of tags assigned to the resource, including those inherited from the provider .
throttle_settings UsagePlanThrottleSettingsArgs
The throttling limits of the usage plan.

Supporting Types

UsagePlanApiStage

ApiId string
API Id of the associated API stage in a usage plan.
Stage string
API stage name of the associated API stage in a usage plan.
ApiId string
API Id of the associated API stage in a usage plan.
Stage string
API stage name of the associated API stage in a usage plan.
apiId string
API Id of the associated API stage in a usage plan.
stage string
API stage name of the associated API stage in a usage plan.
api_id str
API Id of the associated API stage in a usage plan.
stage str
API stage name of the associated API stage in a usage plan.

UsagePlanQuotaSettings

Limit int
The maximum number of requests that can be made in a given time period.
Period string
The time period in which the limit applies. Valid values are “DAY”, “WEEK” or “MONTH”.
Offset int
The number of requests subtracted from the given limit in the initial time period.
Limit int
The maximum number of requests that can be made in a given time period.
Period string
The time period in which the limit applies. Valid values are “DAY”, “WEEK” or “MONTH”.
Offset int
The number of requests subtracted from the given limit in the initial time period.
limit number
The maximum number of requests that can be made in a given time period.
period string
The time period in which the limit applies. Valid values are “DAY”, “WEEK” or “MONTH”.
offset number
The number of requests subtracted from the given limit in the initial time period.
limit int
The maximum number of requests that can be made in a given time period.
period str
The time period in which the limit applies. Valid values are “DAY”, “WEEK” or “MONTH”.
offset int
The number of requests subtracted from the given limit in the initial time period.

UsagePlanThrottleSettings

BurstLimit int
The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
RateLimit double
The API request steady-state rate limit.
BurstLimit int
The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
RateLimit float64
The API request steady-state rate limit.
burstLimit number
The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
rateLimit number
The API request steady-state rate limit.
burst_limit int
The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
rate_limit float
The API request steady-state rate limit.

Import

AWS API Gateway Usage Plan can be imported using the id, e.g.

 $ pulumi import aws:apigateway/usagePlan:UsagePlan myusageplan <usage_plan_id>

Package Details

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