# WebSocketStageAttributes

The attributes used to import existing WebSocketStage.

Extends: [StageAttributes](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.StageAttributes.html)
Used as argument in: [WebSocketStage.fromWebSocketStageAttributes](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.WebSocketStage.html#fromwebsocketstageattributes)

- Source: [`aws-apigatewayv2/lib/websocket/stage.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigatewayv2/lib/websocket/stage.ts#L51)
- Type last changed: v2.112.0 · 1 Dec 2023

## Example

TypeScript:

```ts
declare const webSocketApi: apigwv2.IWebSocketApi;

const importedStage = apigwv2.WebSocketStage.fromWebSocketStageAttributes(this, 'imported-stage', {
  stageName: 'myStage',
  api: webSocketApi,
});

const apiKey = new apigwv2.ApiKey(this, 'MyApiKey');

const usagePlan = new apigwv2.UsagePlan(this, 'MyUsagePlan', {
  apiStages: [{ api: webSocketApi, stage: importedStage }],
});

usagePlan.addApiKey(apiKey);
```

Python:

```python
# web_socket_api: apigwv2.IWebSocketApi

imported_stage = apigwv2.WebSocketStage.from_web_socket_stage_attributes(self, "imported-stage",
    stage_name="myStage",
    api=web_socket_api
)

api_key = apigwv2.ApiKey(self, "MyApiKey")

usage_plan = apigwv2.UsagePlan(self, "MyUsagePlan",
    api_stages=[apigwv2.UsagePlanPerApiStage(api=web_socket_api, stage=imported_stage)]
)

usage_plan.add_api_key(api_key)
```

Java:

```java
IWebSocketApi webSocketApi;

IWebSocketStage importedStage = WebSocketStage.fromWebSocketStageAttributes(this, "imported-stage", WebSocketStageAttributes.builder()
        .stageName("myStage")
        .api(webSocketApi)
        .build());

ApiKey apiKey = new ApiKey(this, "MyApiKey");

UsagePlan usagePlan = UsagePlan.Builder.create(this, "MyUsagePlan")
        .apiStages(List.of(UsagePlanPerApiStage.builder().api(webSocketApi).stage(importedStage).build()))
        .build();

usagePlan.addApiKey(apiKey);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IWebSocketApi webSocketApi;

var importedStage = WebSocketStage.FromWebSocketStageAttributes(this, "imported-stage", new WebSocketStageAttributes {
    StageName = "myStage",
    Api = webSocketApi
});

var apiKey = new ApiKey(this, "MyApiKey");

var usagePlan = new UsagePlan(this, "MyUsagePlan", new UsagePlanProps {
    ApiStages = new [] { new UsagePlanPerApiStage { Api = webSocketApi, Stage = importedStage } }
});

usagePlan.AddApiKey(apiKey);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var webSocketApi IWebSocketApi

importedStage := apigwv2.WebSocketStage_FromWebSocketStageAttributes(this, jsii.String("imported-stage"), &WebSocketStageAttributes{
	StageName: jsii.String("myStage"),
	Api: webSocketApi,
})

apiKey := apigwv2.NewApiKey(this, jsii.String("MyApiKey"))

usagePlan := apigwv2.NewUsagePlan(this, jsii.String("MyUsagePlan"), &UsagePlanProps{
	ApiStages: []UsagePlanPerApiStage{
		&UsagePlanPerApiStage{
			Api: webSocketApi,
			Stage: importedStage,
		},
	},
})

usagePlan.addApiKey(apiKey)
```

## Properties

- `api`: [IWebSocketApi](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IWebSocketApi.html) (required) — The API to which this stage is associated.

- `stageName`: string (required) — The name of the stage.
