Skip to content

How do I get the NamespaceId from a AWS::RedshiftServerless::Namespace in Cloud Formation?

0

I am getting the following error when creating a cloud formation stack: "Requested attribute NamespaceId does not exist in schema for AWS::RedshiftServerless::Namespace". The AWS documentation says it should exist. I am trying to use the attribute to attach a secret to the namespace, but I need the id for the target id. I have tried with to get this both from the NamespaceId and NamespaceArn.

  SecretDbAttachment:
    Type: AWS::SecretsManager::SecretTargetAttachment
    Properties:
      SecretId:
        Ref: DBMasterSecret
      TargetId:
#        !GetAtt RedshiftServerlessNamespace.NamespaceId
        !Select [1, !Split ["/", !GetAtt RedshiftServerlessNamespace.NamespaceArn]]
      TargetType: AWS::RedshiftServerless::Namespace

I'm stuck, how can I make this work?

asked 8 months ago101 views

2 Answers
0
Accepted Answer

Hello.

I think the way CloudFormation is written is incorrect.
The documentation states that "Namespace.NamespaceId" must be specified with GetAtt, so I think it needs to be specified as shown in the CloudFormation below.
Try specifying it like this: "!GetAtt RedshiftServerlessNamespace.Namespace.NamespaceId".
https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-redshiftserverless-namespace.html#aws-resource-redshiftserverless-namespace-return-values

  RedshiftServerlessNamespace:
    Type: AWS::RedshiftServerless::Namespace
    Properties: 
      NamespaceName: "$hoge-redshift-ns"
      AdminUsername: !Ref AdminUsername
      AdminUserPassword: !Ref AdminUserPassword
      KmsKeyId: !Ref KmsKeyId
      DbName: "$hoge-db"
      IamRoles: 
        - !GetAtt RedshiftServerlessRole.Arn

  SecretDbAttachment:
    Type: AWS::SecretsManager::SecretTargetAttachment
    Properties:
      SecretId:
        Ref: DBMasterSecret
      TargetId:
        !GetAtt RedshiftServerlessNamespace.Namespace.NamespaceId
      TargetType: AWS::RedshiftServerless::Namespace
EXPERT

answered 8 months ago

-1

The error you're encountering occurs because NamespaceId is not directly available as a return attribute from the AWS::RedshiftServerless::Namespace resource in CloudFormation.

Looking at the CloudFormation documentation for AWS::RedshiftServerless::Namespace, the NamespaceId is indeed a property of the namespace, but it's not directly exposed as an attribute that can be retrieved using !GetAtt.

The available attributes you can access with !GetAtt for a Redshift Serverless Namespace include:

  • AdminUsername
  • AdminPasswordSecretArn
  • CreationDate
  • DbName
  • DefaultIamRoleArn
  • IamRoles
  • KmsKeyId
  • LogExports
  • NamespaceArn
  • NamespaceName
  • Status

Your second approach using the ARN is the correct way to handle this. The namespace ID is part of the ARN, and you can extract it using the !Split and !Select functions. The format of the ARN is typically:

arn:aws:redshiftserverless:region:account-id:namespace/namespace-id

So your solution to extract the ID from the ARN is appropriate:

TargetId:
!Select [1, !Split ["/", !GetAtt RedshiftServerlessNamespace.NamespaceArn]]

This will extract the namespace ID from the ARN by splitting at the "/" character and selecting the second element (index 1) of the resulting array.
Sources
AWS::RedshiftServerless::Namespace - AWS CloudFormation
AWS::RedshiftServerless::Namespace Namespace - AWS CloudFormation

answered 8 months 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.