- Newest
- Most votes
- Most comments
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
Relevant content
asked a year ago
asked a year ago
asked a year ago
asked a year ago
- AWS OFFICIALUpdated 2 years ago
