- Newest
- Most votes
- Most comments
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
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:
AdminUsernameAdminPasswordSecretArnCreationDateDbNameDefaultIamRoleArnIamRolesKmsKeyIdLogExportsNamespaceArnNamespaceNameStatus
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
