@aws-cdk_aws-apigatewayv2-authorizers-alpha.WebSocketIamAuthorizer

class WebSocketIamAuthorizer 🔹

LanguageType name
.NETAmazon.CDK.AWS.Apigatewayv2.Authorizers.Alpha.WebSocketIamAuthorizer
Gogithub.com/aws/aws-cdk-go/awscdkapigatewayv2authorizersalpha/v2#WebSocketIamAuthorizer
Javasoftware.amazon.awscdk.services.apigatewayv2.authorizers.alpha.WebSocketIamAuthorizer
Pythonaws_cdk.aws_apigatewayv2_authorizers_alpha.WebSocketIamAuthorizer
TypeScript (source)@aws-cdk/aws-apigatewayv2-authorizers-alpha » WebSocketIamAuthorizer

Implements IWebSocketRouteAuthorizer

Authorize WebSocket API Routes with IAM.

Example

import { WebSocketIamAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers-alpha';
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';

// This function handles your connect route
declare const connectHandler: lambda.Function;

const webSocketApi = new apigwv2.WebSocketApi(this, 'WebSocketApi');

webSocketApi.addRoute('$connect', {
  integration: new WebSocketLambdaIntegration('Integration', connectHandler),
  authorizer: new WebSocketIamAuthorizer()
});

// Create an IAM user (identity)
const user = new iam.User(this, 'User');

const webSocketArn = Stack.of(this).formatArn({
  service: 'execute-api',
  resource: webSocketApi.apiId,
});

// Grant access to the IAM user
user.attachInlinePolicy(new iam.Policy(this, 'AllowInvoke', {
  statements: [
    new iam.PolicyStatement({
      actions: ['execute-api:Invoke'],
      effect: iam.Effect.ALLOW,
      resources: [webSocketArn],
    }),
  ],
}));

Initializer

new WebSocketIamAuthorizer()

Methods

NameDescription
bind(_options)🔹Bind this authorizer to a specified WebSocket route.

bind(_options)🔹

public bind(_options: WebSocketRouteAuthorizerBindOptions): WebSocketRouteAuthorizerConfig

Parameters

  • _options WebSocketRouteAuthorizerBindOptions

Returns

  • WebSocketRouteAuthorizerConfig

Bind this authorizer to a specified WebSocket route.