title: Set Secret with Key in AWS Fargate Task from SecretsManager with CDK .NET
body: <p>I've generated a secret in AWS with two key/value pairs. I now want to set my Fargate Task in CDK with both these secrets as Env Variables. I've been through the documentation and am following these two documents:</p>
  <p><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-secrets.html" rel="nofollow noreferrer">Using Secrets Manager to secure sensitive data</a>
  and
  <a href="https://docs.aws.amazon.com/cdk/v2/guide/get_secrets_manager_value.html" rel="nofollow noreferrer">Get a value from AWS Secrets Manager</a></p>
  <p>I'm setting the secrets like so:</p>
  <pre><code>TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions
  {
      ContainerName = &quot;Container name&quot;,
      Image = (...),
      Secrets = new Dictionary&lt;string, Amazon.CDK.AWS.ECS.Secret&gt;
      {
          {&quot;ENV_KEY_1&quot;, Amazon.CDK.AWS.ECS.Secret.FromSecretsManager(Secret.FromSecretCompleteArn(this, &quot;secret-name-1&quot;, &quot;full-arn-1&quot;))},
          {&quot;ENV_KEY_2&quot;, Amazon.CDK.AWS.ECS.Secret.FromSecretsManager(Secret.FromSecretCompleteArn(this, &quot;secret-name-2&quot;, &quot;full-arn-2&quot;))}
      }
  }
  </code></pre>
  <p>According to the documentation (second link), to set a specific key on a secret, I should use something like the following:</p>
  <pre><code>{
    &quot;containerDefinitions&quot;: [{
      &quot;secrets&quot;: [{
        &quot;name&quot;: &quot;environment_variable_name&quot;,
        &quot;valueFrom&quot;: &quot;arn:aws:secretsmanager:region:aws_account_id:secret:appauthexample-AbCdEf:username1::&quot;
      }]
    }]
  }
  </code></pre>
  <p>However, the <strong>Secret.FromSecretCompleteArn</strong> does not support this. It expects only the full arn up to the 6 random characters, and it fails if I add the key (or version).</p>
  <p>I found no way of getting this key to be set. I tried: <strong>Secret.FromNameV2</strong>, <strong>Secret.FromSecretPartialArn</strong> and <strong>Secret.FromAttributes</strong>.</p>