class TokenAuthorizer (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.APIGateway.TokenAuthorizer |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#TokenAuthorizer |
![]() | software.amazon.awscdk.services.apigateway.TokenAuthorizer |
![]() | aws_cdk.aws_apigateway.TokenAuthorizer |
![]() | aws-cdk-lib » aws_apigateway » TokenAuthorizer |
Implements
IConstruct
, IDependable
, IResource
, IAuthorizer
Token based lambda authorizer that recognizes the caller's identity as a bearer token, such as a JSON Web Token (JWT) or an OAuth token.
Based on the token, authorization is performed by a lambda function.
Example
declare const authFn: lambda.Function;
declare const books: apigateway.Resource;
const auth = new apigateway.TokenAuthorizer(this, 'booksAuthorizer', {
handler: authFn
});
books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
authorizer: auth
});
Initializer
new TokenAuthorizer(scope: Construct, id: string, props: TokenAuthorizerProps)
Parameters
- scope
Construct
- id
string
- props
Token
Authorizer Props
Construct Props
Name | Type | Description |
---|---|---|
handler | IFunction | The handler for the authorizer lambda function. |
assume | IRole | An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer. |
authorizer | string | An optional human friendly name for the authorizer. |
identity | string | The request header mapping expression for the bearer token. |
results | Duration | How long APIGateway should cache the results. |
validation | string | An optional regex to be matched against the authorization token. |
handler
Type:
IFunction
The handler for the authorizer lambda function.
The handler must follow a very specific protocol on the input it receives and the output it needs to produce. API Gateway has documented the handler's input specification and output specification.
assumeRole?
Type:
IRole
(optional, default: A resource policy is added to the Lambda function allowing apigateway.amazonaws.com to invoke the function.)
An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer.
The IAM role must be assumable by 'apigateway.amazonaws.com'.
authorizerName?
Type:
string
(optional, default: the unique construct ID)
An optional human friendly name for the authorizer.
Note that, this is not the primary identifier of the authorizer.
identitySource?
Type:
string
(optional, default: IdentitySource.header('Authorization')
)
The request header mapping expression for the bearer token.
This is typically passed as part of the header, in which case
this should be method.request.header.Authorizer
where Authorizer
is the header containing the bearer token.
resultsCacheTtl?
Type:
Duration
(optional, default: Duration.minutes(5))
How long APIGateway should cache the results.
Max 1 hour. Disable caching by setting this to 0.
validationRegex?
Type:
string
(optional, default: no regex filter will be applied.)
An optional regex to be matched against the authorization token.
When matched the authorizer lambda is invoked, otherwise a 401 Unauthorized is returned to the client.
Properties
Name | Type | Description |
---|---|---|
authorizer | string | The ARN of the authorizer to be used in permission policies, such as IAM and resource-based grants. |
authorizer | string | The id of the authorizer. |
authorizer | Cfn | |
env | Resource | The environment this resource belongs to. |
handler | IFunction | The Lambda function handler that this authorizer uses. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
authorization | Authorization | The authorization type of this authorizer. |
rest | string | |
role? | IRole | The IAM role that the API Gateway service assumes while invoking the Lambda function. |
authorizerArn
Type:
string
The ARN of the authorizer to be used in permission policies, such as IAM and resource-based grants.
authorizerId
Type:
string
The id of the authorizer.
authorizerProps
Type:
Cfn
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
handler
Type:
IFunction
The Lambda function handler that this authorizer uses.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
authorizationType?
Type:
Authorization
(optional)
The authorization type of this authorizer.
restApiId?
Type:
string
(optional)
role?
Type:
IRole
(optional)
The IAM role that the API Gateway service assumes while invoking the Lambda function.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
protected lazy | Returns a token that resolves to the Rest Api Id at the time of synthesis. |
protected setup | Sets up the permissions necessary for the API Gateway service to invoke the Lambda function. |
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected lazyRestApiId()
protected lazyRestApiId(): string
Returns
string
Returns a token that resolves to the Rest Api Id at the time of synthesis.
Throws an error, during token resolution, if no RestApi is attached to this authorizer.
protected setupPermissions()
protected setupPermissions(): void
Sets up the permissions necessary for the API Gateway service to invoke the Lambda function.