AWS Classic

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

RestApiPolicy

Provides an API Gateway REST API Policy.

Note: Amazon API Gateway Version 1 resources are used for creating and deploying REST APIs. To create and deploy WebSocket and HTTP APIs, use Amazon API Gateway Version 2 resources.

Example Usage

Basic

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var testRestApi = new Aws.ApiGateway.RestApi("testRestApi", new Aws.ApiGateway.RestApiArgs
        {
        });
        var testRestApiPolicy = new Aws.ApiGateway.RestApiPolicy("testRestApiPolicy", new Aws.ApiGateway.RestApiPolicyArgs
        {
            RestApiId = testRestApi.Id,
            Policy = testRestApi.ExecutionArn.Apply(executionArn => @$"{{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {{
      ""Effect"": ""Allow"",
      ""Principal"": {{
        ""AWS"": ""*""
      }},
      ""Action"": ""execute-api:Invoke"",
      ""Resource"": ""{executionArn}"",
      ""Condition"": {{
        ""IpAddress"": {{
          ""aws:SourceIp"": ""123.123.123.123/32""
        }}
      }}
    }}
  ]
}}
"),
        });
    }

}
package main

import (
	"fmt"

	"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 {
		testRestApi, err := apigateway.NewRestApi(ctx, "testRestApi", nil)
		if err != nil {
			return err
		}
		_, err = apigateway.NewRestApiPolicy(ctx, "testRestApiPolicy", &apigateway.RestApiPolicyArgs{
			RestApiId: testRestApi.ID(),
			Policy: testRestApi.ExecutionArn.ApplyT(func(executionArn string) (string, error) {
				return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Effect\": \"Allow\",\n", "      \"Principal\": {\n", "        \"AWS\": \"*\"\n", "      },\n", "      \"Action\": \"execute-api:Invoke\",\n", "      \"Resource\": \"", executionArn, "\",\n", "      \"Condition\": {\n", "        \"IpAddress\": {\n", "          \"aws:SourceIp\": \"123.123.123.123/32\"\n", "        }\n", "      }\n", "    }\n", "  ]\n", "}\n"), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

test_rest_api = aws.apigateway.RestApi("testRestApi")
test_rest_api_policy = aws.apigateway.RestApiPolicy("testRestApiPolicy",
    rest_api_id=test_rest_api.id,
    policy=test_rest_api.execution_arn.apply(lambda execution_arn: f"""{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Effect": "Allow",
      "Principal": {{
        "AWS": "*"
      }},
      "Action": "execute-api:Invoke",
      "Resource": "{execution_arn}",
      "Condition": {{
        "IpAddress": {{
          "aws:SourceIp": "123.123.123.123/32"
        }}
      }}
    }}
  ]
}}
"""))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const testRestApi = new aws.apigateway.RestApi("testRestApi", {});
const testRestApiPolicy = new aws.apigateway.RestApiPolicy("testRestApiPolicy", {
    restApiId: testRestApi.id,
    policy: pulumi.interpolate`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "execute-api:Invoke",
      "Resource": "${testRestApi.executionArn}",
      "Condition": {
        "IpAddress": {
          "aws:SourceIp": "123.123.123.123/32"
        }
      }
    }
  ]
}
`,
});

Create a RestApiPolicy Resource

new RestApiPolicy(name: string, args: RestApiPolicyArgs, opts?: CustomResourceOptions);
@overload
def RestApiPolicy(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  policy: Optional[str] = None,
                  rest_api_id: Optional[str] = None)
@overload
def RestApiPolicy(resource_name: str,
                  args: RestApiPolicyArgs,
                  opts: Optional[ResourceOptions] = None)
func NewRestApiPolicy(ctx *Context, name string, args RestApiPolicyArgs, opts ...ResourceOption) (*RestApiPolicy, error)
public RestApiPolicy(string name, RestApiPolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RestApiPolicyArgs
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 RestApiPolicyArgs
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 RestApiPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RestApiPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

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

Policy string
JSON formatted policy document that controls access to the API Gateway.
RestApiId string
The ID of the REST API.
Policy string
JSON formatted policy document that controls access to the API Gateway.
RestApiId string
The ID of the REST API.
policy string
JSON formatted policy document that controls access to the API Gateway.
restApiId string
The ID of the REST API.
policy str
JSON formatted policy document that controls access to the API Gateway.
rest_api_id str
The ID of the REST API.

Outputs

All input properties are implicitly available as output properties. Additionally, the RestApiPolicy 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 RestApiPolicy Resource

Get an existing RestApiPolicy 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?: RestApiPolicyState, opts?: CustomResourceOptions): RestApiPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy: Optional[str] = None,
        rest_api_id: Optional[str] = None) -> RestApiPolicy
func GetRestApiPolicy(ctx *Context, name string, id IDInput, state *RestApiPolicyState, opts ...ResourceOption) (*RestApiPolicy, error)
public static RestApiPolicy Get(string name, Input<string> id, RestApiPolicyState? 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:

Policy string
JSON formatted policy document that controls access to the API Gateway.
RestApiId string
The ID of the REST API.
Policy string
JSON formatted policy document that controls access to the API Gateway.
RestApiId string
The ID of the REST API.
policy string
JSON formatted policy document that controls access to the API Gateway.
restApiId string
The ID of the REST API.
policy str
JSON formatted policy document that controls access to the API Gateway.
rest_api_id str
The ID of the REST API.

Import

aws_api_gateway_rest_api_policy can be imported by using the REST API ID, e.g.,

 $ pulumi import aws:apigateway/restApiPolicy:RestApiPolicy example 12345abcde

Package Details

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