Authorizer class
Provides an API Gateway Authorizer.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const demoRestApi = new aws.apigateway.RestApi("demo", {name: "auth-demo"});
const invocationAssumeRole = aws.iam.getPolicyDocument({
statements: [{
principals: [{
type: "Service",
identifiers: ["apigateway.amazonaws.com"],
}],
effect: "Allow",
actions: ["sts:AssumeRole"],
}],
});
const invocationRole = new aws.iam.Role("invocation_role", {
name: "api_gateway_auth_invocation",
path: "/",
assumeRolePolicy: invocationAssumeRole.then(invocationAssumeRole => invocationAssumeRole.json),
});
const lambdaAssumeRole = aws.iam.getPolicyDocument({
statements: [{
principals: [{
type: "Service",
identifiers: ["lambda.amazonaws.com"],
}],
effect: "Allow",
actions: ["sts:AssumeRole"],
}],
});
const lambda = new aws.iam.Role("lambda", {
name: "demo-lambda",
assumeRolePolicy: lambdaAssumeRole.then(lambdaAssumeRole => lambdaAssumeRole.json),
});
const authorizer = new aws.lambda.Function("authorizer", {
code: new pulumi.asset.FileArchive("lambda-function.zip"),
name: "api_gateway_authorizer",
role: lambda.arn,
handler: "exports.example",
sourceCodeHash: std.filebase64sha256({
input: "lambda-function.zip",
}).then(invoke => invoke.result),
});
const demo = new aws.apigateway.Authorizer("demo", {
name: "demo",
restApi: demoRestApi.id,
authorizerUri: authorizer.invokeArn,
authorizerCredentials: invocationRole.arn,
});
const invocationPolicy = aws.iam.getPolicyDocumentOutput({
statements: [{
effect: "Allow",
actions: ["lambda:InvokeFunction"],
resources: [authorizer.arn],
}],
});
const invocationPolicyRolePolicy = new aws.iam.RolePolicy("invocation_policy", {
name: "default",
role: invocationRole.id,
policy: invocationPolicy.json,
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std
demo_rest_api = aws.apigateway.RestApi("demo", name="auth-demo")
invocation_assume_role = aws.iam.get_policy_document(statements=[{
"principals": [{
"type": "Service",
"identifiers": ["apigateway.amazonaws.com"],
}],
"effect": "Allow",
"actions": ["sts:AssumeRole"],
}])
invocation_role = aws.iam.Role("invocation_role",
name="api_gateway_auth_invocation",
path="/",
assume_role_policy=invocation_assume_role.json)
lambda_assume_role = aws.iam.get_policy_document(statements=[{
"principals": [{
"type": "Service",
"identifiers": ["lambda.amazonaws.com"],
}],
"effect": "Allow",
"actions": ["sts:AssumeRole"],
}])
lambda_ = aws.iam.Role("lambda",
name="demo-lambda",
assume_role_policy=lambda_assume_role.json)
authorizer = aws.lambda_.Function("authorizer",
code=pulumi.FileArchive("lambda-function.zip"),
name="api_gateway_authorizer",
role=lambda_.arn,
handler="exports.example",
source_code_hash=std.filebase64sha256(input="lambda-function.zip").result)
demo = aws.apigateway.Authorizer("demo",
name="demo",
rest_api=demo_rest_api.id,
authorizer_uri=authorizer.invoke_arn,
authorizer_credentials=invocation_role.arn)
invocation_policy = aws.iam.get_policy_document_output(statements=[{
"effect": "Allow",
"actions": ["lambda:InvokeFunction"],
"resources": [authorizer.arn],
}])
invocation_policy_role_policy = aws.iam.RolePolicy("invocation_policy",
name="default",
role=invocation_role.id,
policy=invocation_policy.json)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var demoRestApi = new Aws.ApiGateway.RestApi("demo", new()
{
Name = "auth-demo",
});
var invocationAssumeRole = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"apigateway.amazonaws.com",
},
},
},
Effect = "Allow",
Actions = new[]
{
"sts:AssumeRole",
},
},
},
});
var invocationRole = new Aws.Iam.Role("invocation_role", new()
{
Name = "api_gateway_auth_invocation",
Path = "/",
AssumeRolePolicy = invocationAssumeRole.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var lambdaAssumeRole = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"lambda.amazonaws.com",
},
},
},
Effect = "Allow",
Actions = new[]
{
"sts:AssumeRole",
},
},
},
});
var lambda = new Aws.Iam.Role("lambda", new()
{
Name = "demo-lambda",
AssumeRolePolicy = lambdaAssumeRole.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var authorizer = new Aws.Lambda.Function("authorizer", new()
{
Code = new FileArchive("lambda-function.zip"),
Name = "api_gateway_authorizer",
Role = lambda.Arn,
Handler = "exports.example",
SourceCodeHash = Std.Filebase64sha256.Invoke(new()
{
Input = "lambda-function.zip",
}).Apply(invoke => invoke.Result),
});
var demo = new Aws.ApiGateway.Authorizer("demo", new()
{
Name = "demo",
RestApi = demoRestApi.Id,
AuthorizerUri = authorizer.InvokeArn,
AuthorizerCredentials = invocationRole.Arn,
});
var invocationPolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Effect = "Allow",
Actions = new[]
{
"lambda:InvokeFunction",
},
Resources = new[]
{
authorizer.Arn,
},
},
},
});
var invocationPolicyRolePolicy = new Aws.Iam.RolePolicy("invocation_policy", new()
{
Name = "default",
Role = invocationRole.Id,
Policy = invocationPolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/apigateway"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lambda"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
demoRestApi, err := apigateway.NewRestApi(ctx, "demo", &apigateway.RestApiArgs{
Name: pulumi.String("auth-demo"),
})
if err != nil {
return err
}
invocationAssumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"apigateway.amazonaws.com",
},
},
},
Effect: pulumi.StringRef("Allow"),
Actions: []string{
"sts:AssumeRole",
},
},
},
}, nil)
if err != nil {
return err
}
invocationRole, err := iam.NewRole(ctx, "invocation_role", &iam.RoleArgs{
Name: pulumi.String("api_gateway_auth_invocation"),
Path: pulumi.String("/"),
AssumeRolePolicy: pulumi.String(invocationAssumeRole.Json),
})
if err != nil {
return err
}
lambdaAssumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"lambda.amazonaws.com",
},
},
},
Effect: pulumi.StringRef("Allow"),
Actions: []string{
"sts:AssumeRole",
},
},
},
}, nil)
if err != nil {
return err
}
lambda2, err := iam.NewRole(ctx, "lambda", &iam.RoleArgs{
Name: pulumi.String("demo-lambda"),
AssumeRolePolicy: pulumi.String(lambdaAssumeRole.Json),
})
if err != nil {
return err
}
invokeFilebase64sha256, err := std.Filebase64sha256(ctx, &std.Filebase64sha256Args{
Input: "lambda-function.zip",
}, nil)
if err != nil {
return err
}
authorizer, err := lambda.NewFunction(ctx, "authorizer", &lambda.FunctionArgs{
Code: pulumi.NewFileArchive("lambda-function.zip"),
Name: pulumi.String("api_gateway_authorizer"),
Role: lambda2.Arn,
Handler: pulumi.String("exports.example"),
SourceCodeHash: pulumi.String(invokeFilebase64sha256.Result),
})
if err != nil {
return err
}
_, err = apigateway.NewAuthorizer(ctx, "demo", &apigateway.AuthorizerArgs{
Name: pulumi.String("demo"),
RestApi: demoRestApi.ID().ToIDOutput().ToStringOutput(),
AuthorizerUri: authorizer.InvokeArn,
AuthorizerCredentials: invocationRole.Arn,
})
if err != nil {
return err
}
invocationPolicy := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: iam.GetPolicyDocumentStatementArray{
&iam.GetPolicyDocumentStatementArgs{
Effect: pulumi.String("Allow"),
Actions: pulumi.StringArray{
pulumi.String("lambda:InvokeFunction"),
},
Resources: pulumi.StringArray{
authorizer.Arn,
},
},
},
}, nil)
_, err = iam.NewRolePolicy(ctx, "invocation_policy", &iam.RolePolicyArgs{
Name: pulumi.String("default"),
Role: invocationRole.ID().ToIDOutput().ToStringOutput(),
Policy: invocationPolicy.Json(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
std = {
source = "pulumi/std"
}
}
}
data "aws_iam_getpolicydocument" "invocationAssumeRole" {
statements {
principals {
type = "Service"
identifiers = ["apigateway.amazonaws.com"]
}
effect = "Allow"
actions = ["sts:AssumeRole"]
}
}
data "aws_iam_getpolicydocument" "invocationPolicy" {
statements {
effect = "Allow"
actions = ["lambda:InvokeFunction"]
resources = [aws_lambda_function.authorizer.arn]
}
}
data "aws_iam_getpolicydocument" "lambdaAssumeRole" {
statements {
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
effect = "Allow"
actions = ["sts:AssumeRole"]
}
}
resource "aws_apigateway_authorizer" "demo" {
name = "demo"
rest_api = aws_apigateway_restapi.demo.id
authorizer_uri = aws_lambda_function.authorizer.invoke_arn
authorizer_credentials = aws_iam_role.invocation_role.arn
}
resource "aws_apigateway_restapi" "demo" {
name = "auth-demo"
}
resource "aws_iam_role" "invocation_role" {
name = "api_gateway_auth_invocation"
path = "/"
assume_role_policy = data.aws_iam_getpolicydocument.invocationAssumeRole.json
}
resource "aws_iam_rolepolicy" "invocation_policy" {
name = "default"
role = aws_iam_role.invocation_role.id
policy = data.aws_iam_getpolicydocument.invocationPolicy.json
}
resource "aws_iam_role" "lambda" {
name = "demo-lambda"
assume_role_policy = data.aws_iam_getpolicydocument.lambdaAssumeRole.json
}
resource "aws_lambda_function" "authorizer" {
code = fileArchive("lambda-function.zip")
name = "api_gateway_authorizer"
role = aws_iam_role.lambda.arn
handler = "exports.example"
source_code_hash = filebase64sha256("lambda-function.zip")
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.apigateway.RestApi;
import com.pulumi.aws.apigateway.RestApiArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.lambda.Function;
import com.pulumi.aws.lambda.FunctionArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.Filebase64sha256Args;
import com.pulumi.aws.apigateway.Authorizer;
import com.pulumi.aws.apigateway.AuthorizerArgs;
import com.pulumi.aws.iam.RolePolicy;
import com.pulumi.aws.iam.RolePolicyArgs;
import com.pulumi.asset.FileArchive;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var demoRestApi = new RestApi("demoRestApi", RestApiArgs.builder()
.name("auth-demo")
.build());
final var invocationAssumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("apigateway.amazonaws.com")
.build())
.effect("Allow")
.actions("sts:AssumeRole")
.build())
.build());
var invocationRole = new Role("invocationRole", RoleArgs.builder()
.name("api_gateway_auth_invocation")
.path("/")
.assumeRolePolicy(invocationAssumeRole.json())
.build());
final var lambdaAssumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("lambda.amazonaws.com")
.build())
.effect("Allow")
.actions("sts:AssumeRole")
.build())
.build());
var lambda = new Role("lambda", RoleArgs.builder()
.name("demo-lambda")
.assumeRolePolicy(lambdaAssumeRole.json())
.build());
var authorizer = new Function("authorizer", FunctionArgs.builder()
.code(new FileArchive("lambda-function.zip"))
.name("api_gateway_authorizer")
.role(lambda.arn())
.handler("exports.example")
.sourceCodeHash(StdFunctions.filebase64sha256(Filebase64sha256Args.builder()
.input("lambda-function.zip")
.build()).result())
.build());
var demo = new Authorizer("demo", AuthorizerArgs.builder()
.name("demo")
.restApi(demoRestApi.id())
.authorizerUri(authorizer.invokeArn())
.authorizerCredentials(invocationRole.arn())
.build());
final var invocationPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.actions("lambda:InvokeFunction")
.resources(authorizer.arn())
.build())
.build());
var invocationPolicyRolePolicy = new RolePolicy("invocationPolicyRolePolicy", RolePolicyArgs.builder()
.name("default")
.role(invocationRole.id())
.policy(invocationPolicy.applyValue(_invocationPolicy -> _invocationPolicy.json()))
.build());
}
}
resources:
demo:
type: aws:apigateway:Authorizer
properties:
name: demo
restApi: ${demoRestApi.id}
authorizerUri: ${authorizer.invokeArn}
authorizerCredentials: ${invocationRole.arn}
demoRestApi:
type: aws:apigateway:RestApi
name: demo
properties:
name: auth-demo
invocationRole:
type: aws:iam:Role
name: invocation_role
properties:
name: api_gateway_auth_invocation
path: /
assumeRolePolicy: ${invocationAssumeRole.json}
invocationPolicyRolePolicy:
type: aws:iam:RolePolicy
name: invocation_policy
properties:
name: default
role: ${invocationRole.id}
policy: ${invocationPolicy.json}
lambda:
type: aws:iam:Role
properties:
name: demo-lambda
assumeRolePolicy: ${lambdaAssumeRole.json}
authorizer:
type: aws:lambda:Function
properties:
code:
fn::fileArchive: lambda-function.zip
name: api_gateway_authorizer
role: ${lambda.arn}
handler: exports.example
sourceCodeHash:
fn::invoke:
function: std:filebase64sha256
arguments:
input: lambda-function.zip
return: result
variables:
invocationAssumeRole:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- principals:
- type: Service
identifiers:
- apigateway.amazonaws.com
effect: Allow
actions:
- sts:AssumeRole
invocationPolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- effect: Allow
actions:
- lambda:InvokeFunction
resources:
- ${authorizer.arn}
lambdaAssumeRole:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- principals:
- type: Service
identifiers:
- lambda.amazonaws.com
effect: Allow
actions:
- sts:AssumeRole
Import
Using pulumi import, import AWS API Gateway Authorizer using the REST-API-ID/AUTHORIZER-ID. For example:
$ pulumi import aws:apigateway/authorizer:Authorizer authorizer 12345abcde/example
Constructors
- Authorizer(String name, {AuthorizerArgs? args, CustomResourceOptions? options})
-
Creates a new Authorizer.
nameThe Pulumi resource name.argsArguments used to configure this Authorizer. The set of arguments for Authorizer.optionsResource options controlling this resource's behavior. - Authorizer.reference(String urn)
- Creates a typed reference to an existing Authorizer resource.
Properties
-
arn
↔ Output<
String> -
ARN of the API Gateway Authorizer
latefinal
-
Credentials required for the authorizer. To specify an IAM Role for API Gateway to assume, use the IAM Role ARN.
latefinal
-
TTL of cached authorizer results in seconds. Defaults to
300.latefinal -
Authorizer's URI. This must be a well-formed Lambda function URI in the form of
arn:aws:apigateway:{region}:lambda:path/{service_api}, e.g.,arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:012345678912:function:my-function/invocationslatefinal -
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
identitySource
↔ Output<
String?> -
Source of the identity in an incoming request. Defaults to
method.request.header.Authorization. ForREQUESTtype, this may be a comma-separated list of values, including headers, query string parameters and stage variables - e.g.,"method.request.header.SomeHeaderName,method.request.querystring.SomeQueryStringName,stageVariables.SomeStageVariableName"latefinal -
identityValidationExpression
↔ Output<
String?> -
Validation expression for the incoming identity. For
TOKENtype, this value should be a regular expression. The incoming token from the client is matched against this expression, and will proceed if the token matches. If the token doesn't match, the client receives a 401 Unauthorized response.latefinal - isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
name
↔ Output<
String> -
Name of the authorizer
latefinal
-
providerArns
↔ Output<
List< String> ?> -
List of the Amazon Cognito user pool ARNs. Each element is of this format:
arn:aws:cognito-idp:{region}:{account_id}:userpool/{user_pool_id}.latefinal -
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
-
restApi
↔ Output<
String> -
ID of the associated REST API
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
type
↔ Output<
String?> -
Type of the authorizer. Possible values are
TOKENfor a Lambda function using a single authorization token submitted in a custom header,REQUESTfor a Lambda function using incoming request parameters, orCOGNITO_USER_POOLSfor using an Amazon Cognito user pool. Defaults toTOKEN.latefinal -
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {AuthorizerState? state, CustomResourceOptions? options}) → Authorizer -
Gets an existing Authorizer resource's state with the given
nameandid.