aws / aws/aws-sam-cli

Getting "Could not find a value associated with JSONKey in SecretString" after updating secret

Open
#2,153 13 comments 13 reactions 0 assignees View on GitHub
maintainer/need-response stage/needs-investigation
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description

Our SAM template references some secrets, as follow:

```yaml
FOO_VAR: {{resolve:secretsmanager:FOO_SECRET:SecretString:foo}}
```

This morning we added a new key in the secret `FOO` (from console), and we wanted to update our SAM application to use this new key. Also, we removed an unused key. Though, stack deployment fails with the following error:

`Could not find a value associated with JSONKey in SecretString`

### Steps to reproduce

1. Create a Secret in SecretManager from AWS Console (`FOO_SECRET`) and put one key/value in the secret (`foo:bar`)
2. Create a stack using SAM application default template
3. Within the template, reference the secret key created in step 1 as follow: `{{resolve:secretsmanager:FOO_SECRET:SecretString:foo}}`
4. Deploy your stack
5. Go in SecretsManager from the AWS Console and edit `FOO_SECRET` adding the following key: `willFail: true` and removing the old one (`foo`)
6. Within the template, remove the reference to `foo` and add the reference to the newly created secret key from step 5, as follow:
`{{resolve:secretsmanager:FOO_SECRET:SecretString:willFail}}`
7. Deploy your stack

### Observed result

You'll get `Could not find a value associated with JSONKey in SecretString`, that (presumably) means that CloudFormation is trying to resolve `foo` which doesn't exist anymore.

### Expected result

Deployment should work as no more references to `foo` exist in the template.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: Mac OS 10.15.5
2. `sam --version`: SAM CLI, version 0.53.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.