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: 
**Nested Stack Names** contain a random hash.

To overcome the problem, pass the `AWS::StackName` as a parameter to the nested stack, from the root/master stack.

---

In the example below, the `AWS::StackName` is passed as a parameter.

**master.yaml**

```
Resources:
  S3:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://s3-ap-southeast-2.amazonaws.com/...s3.yaml
      Parameters:
        ParamStackName: !Ref AWS::StackName

```

---

**s3.yaml** Notice: `!Ref AWS::StackName` while **nested**, will include a random hash.

```
 Parameters:
    ParamStackName:
      Type: String

 Resources:
    MyS3:
      Type: AWS::S3::Bucket
      Properties:
        # Using !Ref AWS::StackName will include the random hash
        BucketName: !Ref ParamStackName

```
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"] ] ] ] 

```