Class Authorizer


  • public class Authorizer
    extends com.pulumi.resources.CustomResource
    Provides an API Gateway Authorizer. ## Example Usage
     
     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());
     
         }
     }
     
     
    ## Import Using `pulumi import`, import AWS API Gateway Authorizer using the `REST-API-ID/AUTHORIZER-ID`. For example: ```sh $ pulumi import aws:apigateway/authorizer:Authorizer authorizer 12345abcde/example ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.pulumi.core.Output<java.lang.String> arn()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> authorizerCredentials()  
      com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> authorizerResultTtlInSeconds()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> authorizerUri()  
      static Authorizer get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, AuthorizerState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> identitySource()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> identityValidationExpression()  
      com.pulumi.core.Output<java.lang.String> name()  
      com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> providerArns()  
      com.pulumi.core.Output<java.lang.String> region()  
      com.pulumi.core.Output<java.lang.String> restApi()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> type()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Authorizer

        public Authorizer​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • Authorizer

        public Authorizer​(java.lang.String name,
                          AuthorizerArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • Authorizer

        public Authorizer​(java.lang.String name,
                          AuthorizerArgs args,
                          @Nullable
                          com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • arn

        public com.pulumi.core.Output<java.lang.String> arn()
        Returns:
        ARN of the API Gateway Authorizer
      • authorizerCredentials

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> authorizerCredentials()
        Returns:
        Credentials required for the authorizer. To specify an IAM Role for API Gateway to assume, use the IAM Role ARN.
      • authorizerResultTtlInSeconds

        public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> authorizerResultTtlInSeconds()
        Returns:
        TTL of cached authorizer results in seconds. Defaults to `300`.
      • authorizerUri

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> authorizerUri()
        Returns:
        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/invocations`
      • identitySource

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> identitySource()
        Returns:
        Source of the identity in an incoming request. Defaults to `method.request.header.Authorization`. For `REQUEST` type, 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"`
      • identityValidationExpression

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> identityValidationExpression()
        Returns:
        Validation expression for the incoming identity. For `TOKEN` type, 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.
      • name

        public com.pulumi.core.Output<java.lang.String> name()
        Returns:
        Name of the authorizer
      • providerArns

        public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> providerArns()
        Returns:
        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}`.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • restApi

        public com.pulumi.core.Output<java.lang.String> restApi()
        Returns:
        ID of the associated REST API
      • type

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> type()
        Returns:
        Type of the authorizer. Possible values are `TOKEN` for a Lambda function using a single authorization token submitted in a custom header, `REQUEST` for a Lambda function using incoming request parameters, or `COGNITO_USER_POOLS` for using an Amazon Cognito user pool. Defaults to `TOKEN`.
      • get

        public static Authorizer get​(java.lang.String name,
                                     com.pulumi.core.Output<java.lang.String> id,
                                     @Nullable
                                     AuthorizerState state,
                                     @Nullable
                                     com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.