ArnComponents Struct
| Source | core/lib/arn.ts |
|---|---|
| Type last changed |
Example
ts
import { WebSocketIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
import { WebSocketLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
// 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],
}),
],
}));
python
from aws_cdk.aws_apigatewayv2_authorizers import WebSocketIamAuthorizer
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
# This function handles your connect route
# connect_handler: lambda.Function
web_socket_api = apigwv2.WebSocketApi(self, "WebSocketApi")
web_socket_api.add_route("$connect",
integration=WebSocketLambdaIntegration("Integration", connect_handler),
authorizer=WebSocketIamAuthorizer()
)
# Create an IAM user (identity)
user = iam.User(self, "User")
web_socket_arn = Stack.of(self).format_arn(
service="execute-api",
resource=web_socket_api.api_id
)
# Grant access to the IAM user
user.attach_inline_policy(iam.Policy(self, "AllowInvoke",
statements=[
iam.PolicyStatement(
actions=["execute-api:Invoke"],
effect=iam.Effect.ALLOW,
resources=[web_socket_arn]
)
]
))
java
import software.amazon.awscdk.aws_apigatewayv2_authorizers.WebSocketIamAuthorizer;
import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketLambdaIntegration;
// This function handles your connect route
Function connectHandler;
WebSocketApi webSocketApi = new WebSocketApi(this, "WebSocketApi");
webSocketApi.addRoute("$connect", WebSocketRouteOptions.builder()
.integration(new WebSocketLambdaIntegration("Integration", connectHandler))
.authorizer(new WebSocketIamAuthorizer())
.build());
// Create an IAM user (identity)
User user = new User(this, "User");
String webSocketArn = Stack.of(this).formatArn(ArnComponents.builder()
.service("execute-api")
.resource(webSocketApi.getApiId())
.build());
// Grant access to the IAM user
user.attachInlinePolicy(Policy.Builder.create(this, "AllowInvoke")
.statements(List.of(
PolicyStatement.Builder.create()
.actions(List.of("execute-api:Invoke"))
.effect(Effect.ALLOW)
.resources(List.of(webSocketArn))
.build()))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AwsApigatewayv2Authorizers;
using Amazon.CDK.AwsApigatewayv2Integrations;
// This function handles your connect route
Function connectHandler;
var webSocketApi = new WebSocketApi(this, "WebSocketApi");
webSocketApi.AddRoute("$connect", new WebSocketRouteOptions {
Integration = new WebSocketLambdaIntegration("Integration", connectHandler),
Authorizer = new WebSocketIamAuthorizer()
});
// Create an IAM user (identity)
var user = new User(this, "User");
var webSocketArn = Stack.Of(this).FormatArn(new ArnComponents {
Service = "execute-api",
Resource = webSocketApi.ApiId
});
// Grant access to the IAM user
user.AttachInlinePolicy(new Policy(this, "AllowInvoke", new PolicyProps {
Statements = new [] {
new PolicyStatement(new PolicyStatementProps {
Actions = new [] { "execute-api:Invoke" },
Effect = Effect.ALLOW,
Resources = new [] { webSocketArn }
}) }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
// This function handles your connect route
var connectHandler Function
webSocketApi := apigwv2.NewWebSocketApi(this, jsii.String("WebSocketApi"))
webSocketApi.AddRoute(jsii.String("$connect"), &WebSocketRouteOptions{
Integration: awscdk.NewWebSocketLambdaIntegration(jsii.String("Integration"), connectHandler),
Authorizer: awscdk.NewWebSocketIamAuthorizer(),
})
// Create an IAM user (identity)
user := iam.NewUser(this, jsii.String("User"))
webSocketArn := awscdk.stack_Of(this).FormatArn(&ArnComponents{
Service: jsii.String("execute-api"),
Resource: webSocketApi.ApiId,
})
// Grant access to the IAM user
user.AttachInlinePolicy(iam.NewPolicy(this, jsii.String("AllowInvoke"), &PolicyProps{
Statements: []PolicyStatement{
iam.NewPolicyStatement(&PolicyStatementProps{
Actions: []*string{
jsii.String("execute-api:Invoke"),
},
Effect: iam.Effect_ALLOW,
Resources: []*string{
webSocketArn,
},
}),
},
}))
Properties
accountoptionalstringaccountoptionalstraccountoptionalStringAccountoptionalstringAccountoptional*string #The ID of the AWS account that owns the resource, without the hyphens.
Default: The account the stack is deployed to.
For example, 123456789012. Note that the ARNs for some resources don't require an account number, so this component might be omitted.
arnFormatoptionalArnFormatarn_formatoptionalArnFormatarnFormatoptionalArnFormatArnFormatoptionalArnFormatArnFormatoptionalArnFormat #The specific ARN format to use for this ARN value.
Default: ':' when arnFormat is COLON_RESOURCE_NAME, '/' otherwise. The deprecated sep property takes precedence when specified.
partitionoptionalstringpartitionoptionalstrpartitionoptionalStringPartitionoptionalstringPartitionoptional*string #The partition that the resource is in.
Default: The AWS partition the stack is deployed to.
For standard AWS regions, the partition is aws. If you have resources in other partitions, the partition is aws-partitionname. For example, the partition for resources in the China (Beijing) region is aws-cn.
regionoptionalstringregionoptionalstrregionoptionalStringRegionoptionalstringRegionoptional*string #The region the resource resides in.
Default: The region the stack is deployed to.
Note that the ARNs for some resources do not require a region, so this component might be omitted.
Resource type (e.g. "table", "autoScalingGroup", "certificate"). For some resource types, e.g. S3 buckets, this field defines the bucket name.
resourceNameoptionalstringresource_nameoptionalstrresourceNameoptionalStringResourceNameoptionalstringResourceNameoptional*string #Resource name or path within the resource (i.e. S3 bucket object key) or a wildcard such as ``"*"``. This is service-dependent.
The service namespace that identifies the AWS product (for example, 's3', 'iam', 'codepipeline').