- Newest
- Most votes
- Most comments
Based on your description of the errors, it seems you're having trouble accessing the ARN of a Redshift Serverless workgroup in AWS CDK to use it in IAM policies.
When working with a CfnWorkgroup in AWS CDK, the correct attribute to access the workgroup ARN is attr_workgroup_arn, not attr_workgroup. However, there appears to be some confusion in the error messages you're seeing.
Here's the correct way to reference a Redshift Serverless workgroup ARN in an IAM policy within the same stack:
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()
This will correctly reference the full ARN including the UUID that gets generated when the workgroup is created.
Sources
Workgroup - Amazon Redshift Serverless
CfnWorkgroup — AWS Cloud Development Kit 2.232.0 documentation
CfnWorkgroupPropsMixin — AWS Cloud Development Kit 2.232.0 documentation
answered 10 months ago
Relevant content
asked 10 months ago
asked 10 months ago
asked 10 months ago
asked 10 months ago
- AWS OFFICIALUpdated 2 years ago
