Skip to content

Redshift Serverless workgroup arn error

0

from aws_cdk import ( aws_redshiftserverless as redshiftserverless, aws_iam as iam, Stack ) from constructs import Construct

class MyStack(Stack): def init(self, scope: Construct, id: str, **kwargs): super().init(scope, id, **kwargs)

Create a Redshift Serverless workgroup workgroup = redshiftserverless.CfnWorkgroup( self, "MyWorkgroup", workgroup_name="my-workgroup", namespace_name="my-namespace"

Add other required properties )

Create an IAM role with a policy that references the workgroup ARN role = iam.Role( self, "MyRole", assumed_by=iam.ServicePrincipal("lambda.amazonaws.com") )

Add a policy that references the workgroup ARN role.add_to_policy( iam.PolicyStatement( actions=["redshift-serverless:GetWorkgroup"], resources=[workgroup.get_att("workgroupArn").to_string()] ) ) The key here is using workgroup.get_att("workgroupArn").to_string() to correctly reference the workgroup ARN. This approach uses CloudFormation's GetAtt function to retrieve the ARN attribute of the workgroup resource.

If you're using TypeScript, the equivalent would be:

workgroup.getAtt('workgroupArn').toString()

on using above got Requested attribute workgroupArn does not exist in schema for AWS::RedshiftServerless::Workgroup also tried

Using workgroup.attr_workgroup or workgroup.attr_workgroup_arn resources=[workgroup.attr_workgroup] Error: TypeError: type of argument resources must be one of (Sequence[str], NoneType); got aws_cdk.Reference instead

Trying to use workgroup.ref to construct ARN manually workgroup_arn = f"arn:aws:redshift-serverless:{self.region}:{self.account}:workgroup/{workgroup.ref}" resources=[workgroup_arn] Problem: workgroup.ref returns the workgroup name, not the UUID.

Using a Python list directly resources=[workgroup.attr_workgroup] Error: TypeError: type of argument resources must be one of (Sequence[str], NoneType); got list in

Using attr_workgroup_arn resources=[workgroup.attr_workgroup_arn] Error: AttributeError: 'CfnWorkgroup' object has no attribute 'attr_workgroup_arn'. Did you mean: 'attr_workgroup'?

When using AWS CDK to create a Redshift Serverless Workgroup (CfnWorkgroup), there is no property to retrieve the workgroup’s ARN or UUID.

This causes issues when creating IAM policies that require the workgroup ARN (UUID-based). Attempts to use workgroup.ref, attr_workgroup, or attr_workgroup_arn either produce the name instead of UUID or result in type errors:

AttributeError: 'CfnWorkgroup' object has no attribute 'attr_workgroup_arn'

TypeError: type of argument resources must be one of (Sequence[str], NoneType); got aws_cdk.Reference instead

When working with Amazon Redshift Serverless workgroups in AWS CDK, the ARN format is important to get right. The correct format for a Redshift Serverless workgroup ARN follows this pattern:

arn:aws(-[a-z]+)*:redshift-serverless:[a-z]{2}(-gov|(-iso[a-z]?))?-[a-z]+-\d{1}:\d{12}:workgroup/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}

You're seeing workgroup/workgroup name instead of workgroup/uuid because you might be using a reference to the workgroup name rather than the actual ARN that gets generated when the resource is created.

The workgroup ARN should include a UUID after the "workgroup/" part, which is automatically generated when the workgroup is created. This UUID is part of the workgroup's unique identifier.

When using the AWS CDK, you should reference the workgroup's ARN using attr_workgroup_arn property, which will give you the complete ARN including the UUID. This property links to the actual ARN that gets created in AWS, matching what you would see in the AWS console.

Make sure you're using the workgroupArn property from the WorkgroupProperty interface or the attr_workgroup_arn attribute from a CfnWorkgroup instance to get the correct ARN format with the UUID.

when used this got above multiple error

from aws_cdk import ( aws_redshiftserverless as redshiftserverless, aws_iam as iam, Stack, Fn ) from constructs import Construct

class MyStack(Stack): def init(self, scope: Construct, id: str, **kwargs): super().init(scope, id, **kwargs)

Create a Redshift Serverless workgroup

workgroup = redshiftserverless.CfnWorkgroup( self, "MyWorkgroup", workgroup_name="my-workgroup", namespace_name="my-namespace"

Add other required properties

)

Construct the ARN manually using the correct format

workgroup_arn = Fn.join("", [ f"arn:aws:redshift-serverless:{self.region}:{self.account}:workgroup/", workgroup.ref ])

Create an IAM role with a policy that references the workgroup ARN

role = iam.Role( self, "MyRole", assumed_by=iam.ServicePrincipal("lambda.amazonaws.com") )

Add a policy that references the workgroup ARN

role.add_to_policy( iam.PolicyStatement( actions=["redshift-serverless:GetWorkgroup"], resources=[workgroup_arn] ) ) The key issue is that for Redshift Serverless workgroups, the ref attribute returns the workgroup ID (which includes the UUID), not just the name. This is different from what you expected. By constructing the ARN manually with Fn.join(), you can create the proper ARN format that includes the workgroup ID.

when used above workgroup_arn = Fn.join("", [ f"arn:aws:redshift-serverless:{self.region}:{self.account}:workgroup/", workgroup.ref ])

this doesnt returns the workgroup ID (which includes the UUID), but shows name after workgroup/

please suggest cdk code tried everything

asked a year ago113 views

1 Answer
0

When working with Amazon Redshift Serverless workgroups in AWS CDK, constructing the correct ARN format can be challenging. The issue you're encountering is that the ref attribute for a Redshift Serverless workgroup returns the workgroup name, not the UUID that's required in the ARN pattern.

For Redshift Serverless workgroups, the ARN follows this pattern: arn:aws:redshift-serverless:{region}:{account}:workgroup/{uuid}

Where the UUID is a generated identifier, not simply the workgroup name.

Here's a solution that should work for your CDK code:

from aws_cdk import (
aws_redshiftserverless as redshiftserverless,
aws_iam as iam,
Stack,
Fn,
CfnOutput
)
from constructs import Construct

class MyStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)

# Create a Redshift Serverless namespace first
namespace = redshiftserverless.CfnNamespace(
self, "MyNamespace",
namespace_name="my-namespace",
# Add other required properties
)

# Create a Redshift Serverless workgroup
workgroup = redshiftserverless.CfnWorkgroup(
self, "MyWorkgroup",
workgroup_name="my-workgroup",
namespace_name=namespace.namespace_name,
# Add other required properties
)

# Make sure workgroup depends on namespace
workgroup.add_depends_on(namespace)

# Use the GetAtt function to get the workgroup ARN
# This is the correct way to get the full ARN with UUID
workgroup_arn = Fn.get_att(workgroup.logical_id, "WorkgroupArn").to_string()

# Create an IAM role with a policy that references the workgroup ARN
role = iam.Role(
self, "MyRole",
assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
)

# Add a policy that references the workgroup ARN
role.add_to_policy(
iam.PolicyStatement(
actions=["redshift-serverless:GetCredentials"],
resources=[workgroup_arn]
)
)

# Output the workgroup ARN for verification
CfnOutput(self, "WorkgroupARN", value=workgroup_arn)

The key difference is using Fn.get_att(workgroup.logical_id, "WorkgroupArn").to_string() to retrieve the full ARN with the UUID. The GetAtt CloudFormation function can access the WorkgroupArn attribute that's available after the workgroup is created.

This approach correctly references the full ARN including the UUID portion, which is necessary for IAM policies that need to reference the Redshift Serverless workgroup.

If you're still encountering issues, you could also consider using a custom resource or the AWS CDK escape hatch to get the workgroup ARN after deployment, but the approach above should work for most scenarios.
Sources
AWS::Bedrock::KnowledgeBase RedshiftServerlessConfiguration - AWS CloudFormation
Ingest data from Google Analytics 4 and Google Sheets to Amazon Redshift using Amazon AppFlow | AWS Big Data Blog

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.