- Newest
- Most votes
- Most comments
To correctly reference a Redshift Serverless workgroup ARN in your AWS CDK code, you need to use the proper attribute and format. The issue you're encountering is that the CfnWorkgroup class doesn't directly expose an attribute for the workgroup ARN.
Here's how you can correctly reference the workgroup ARN in your IAM policy:
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.
If you need to reference the workgroup ARN in other parts of your CDK code or in cross-account scenarios, you'll need to follow the same pattern of constructing the ARN manually using the workgroup's ref attribute.
For cross-account scenarios, you would need to specify the account ID explicitly rather than using self.account if the workgroup is in a different account.
Sources
AWS::Bedrock::KnowledgeBase RedshiftServerlessConfiguration - AWS CloudFormation
How to Set Up Cross-Account Amazon MSK to Redshift Streaming Over Private Network | AWS re:Post
answered 9 months ago
Relevant content
asked 9 months ago
asked 9 months ago
asked 9 months ago
asked 9 months ago
- AWS OFFICIALUpdated 2 years ago
