Question: How can one get the AWS::StackName without the random generate part?

I create a stack: `aws cloudformation create-stack --stack-name test`

The stack name returned when evaluated using `AWS:StackName` will included a random generated part, e.g. `test-KB0IKRIHP9PH`

What I really want returned is the parameter without the generated part, in this case `test`,
omitting `-KB0IKRIHP9PH`

---

My use case for this is, when my containers startup, they need to get database
credential from a pre created named secret. With the random part in place the service all fail to start initially until the secrets are created.

In the code below I assign the StackName to an environment variable.

```
TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Name: website-service
          Environment:
            - Name: ENVIRONMENT_VAR
              Value: !Join ["", ["CF_", {"Ref": "AWS::StackName"}]]

```

---

Here is an update as requested, to show how I create the stack. I am using a MakeFile...

```
create-test: s3
    @ip_address=$$(dig @resolver1.opendns.com ANY myip.opendns.com     +short); \
    read -s -p "Enter DB Root Password: "  pswd; \
    [[ -z $$pswd ]] && exit 1 || \
    aws cloudformation create-stack \
    --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
    --stack-name test \
    --template-body file://master.yaml \
    --parameters ParameterKey=DBRootPassword,ParameterValue=$$pswd \
    ParameterKey=DBHostAccessCidr,ParameterValue=$$ip_address/32

```

Answer: 
I test this with a simple template:

```yaml
AWSTemplateFormatVersion: 2010-09-09

Resources:

  Bucket:
    Type: AWS::S3::Bucket

Outputs:

  Stack:
    Value: !Sub ${AWS::StackName}

```

The **Stack** output variable exactly matched the name of the stack that I created. There were *no* random characters.

I launched the stack via the console.
If `AWS::StackName` is in the form of `test-KB0IKRIHP9PH`, then you can get `test` and perform the Join as follows:

```
Environment:
  - Name: ENVIRONMENT_VAR
    Value: !Join ["", ["CD_", !Select [0, !Split ['-', !Ref "AWS::StackName"] ] ] ] 

```