aws-amplify / aws-amplify/amplify-cli
Function env vars SSM Parameters missing in PR deploy previews, feature-branch deployments
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
CLI version 12.2.0-rc.a3b139fb36.0
---
Hello Team,
I see that that the issue was fixed linked with PR.
I tested this with Amplify CLI Version - 12.2.0-rc.a3b139fb36.0 and observe similar issue
Steps of Reproduction
1. created sample react project.
2. `amplify init -y`
3. `amplify add function` (make sure you add environment variables to the function)
4. initialize git repo and git push
5. Deploy this master/main branch using CI/CD on Amplify console. The build would be triggered and deployed successfully.
6. enable pr preview on amplify console with option "Create new backend environment"
7. On local -> `git checkout -b testbranch`
8. make some changes in index.js of lambda function.
9. Commit and push to git repo
10. raise PR with main/master branch which is already hosted on amplify
11. The PR build will create a new backend environment with random name and would get failed with error shown in build logs below -
```
2023-07-12T06:13:53.961Z [INFO]: # Retrieving environment cache...
2023-07-12T06:13:53.993Z [WARNING]: ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})}
2023-07-12T06:13:53.993Z [INFO]: ---- Setting Up SSM Secrets ----
2023-07-12T06:13:53.993Z [INFO]: SSM params {"Path":"/amplify/d1d2qz3ywham00/prg/","WithDecryption":true}
2023-07-12T06:14:11.144Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 10.5.2 to 12.2.0-rc.a3b139fb36.0...
2023-07-12T06:14:27.556Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 12.2.0-rc.a3b139fb36.0
2023-07-12T06:14:27.641Z [INFO]: # Retrieving cache...
2023-07-12T06:14:27.666Z [INFO]: # Retrieved cache
2023-07-12T06:14:31.785Z [INFO]: ## Starting Backend Build
# Starting phase: build
2023-07-12T06:14:33.654Z [INFO]: [33mNote: It is recommended to run this command from the root of your app directory[39m
2023-07-12T06:14:33.958Z [INFO]: [0mAmplify AppID found: d1d2qz3ywham00. Amplify App name is: reactmultipage[0m
2023-07-12T06:14:34.012Z [INFO]: [0mAdding backend environment prg to AWS Amplify app: d1d2qz3ywham00[0m
2023-07-12T06:14:39.605Z [INFO]:
2023-07-12T06:14:39.610Z [INFO]: CREATE_IN_PROGRESS amplify-reactmultipage-prg-61433 AWS::CloudFormation::Stack Wed Jul 12 2023 06:14:34 GMT+0000 (Coordinated Universal Time) User Initiated
CREATE_IN_PROGRESS UnauthRole AWS::IAM::Role Wed Jul 12 2023 06:14:37 GMT+0000 (Coordinated Universal Time)
CREATE_IN_PROGRESS AuthRole AWS::IAM::Role Wed Jul 12 2023 06:14:37 GMT+0000 (Coordinated Universal Time)
CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Wed Jul 12 2023 06:14:37 GMT+0000 (Coordinated Universal Time)
CREATE_IN_PROGRESS UnauthRole AWS::IAM::Role Wed Jul 12 2023 06:14:38 GMT+0000 (Coordinated Universal Time) Resource creation Initiated
CREATE_IN_PROGRESS AuthRole AWS::IAM::Role Wed Jul 12 2023 06:14:38 GMT+0000 (Coordinated Universal Time) Resource creation Initiated
CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Wed Jul 12 2023 06:14:38 GMT+0000 (Coordinated Universal Time) Resource creation Initiated
2023-07-12T06:14:54.593Z [INFO]:
2023-07-12T06:14:54.594Z [INFO]: CREATE_COMPLETE UnauthRole AWS::IAM::Role Wed Jul 12 2023 06:14:51 GMT+0000 (Coordinated Universal Time)
CREATE_COMPLETE AuthRole AWS::IAM::Role Wed Jul 12 2023 06:14:51 GMT+0000 (Coordinated Universal Time)
2023-07-12T06:15:04.660Z [INFO]: [K
2023-07-12T06:15:04.867Z [INFO]: [K
2023-07-12T06:15:04.918Z [INFO]: [1A[K
2023-07-12T06:15:04.929Z [WARNING]: - Uploading files.
2023-07-12T06:15:04.969Z [INFO]: [1A
2023-07-12T06:15:04.969Z [INFO]: [K
2023-07-12T06:15:05.020Z [INFO]: [1A
2023-07-12T06:15:05.020Z [INFO]: [K
2023-07-12T06:15:05.084Z [INFO]: [1A[K
2023-07-12T06:15:05.135Z [INFO]: [1A
2023-07-12T06:15:05.136Z [INFO]: [K
2023-07-12T06:15:05.185Z [INFO]: [1A[K
2023-07-12T06:15:05.189Z [INFO]: [1A
2023-07-12T06:15:05.190Z [INFO]: [K
2023-07-12T06:15:05.191Z [WARNING]: - Uploading files.
2023-07-12T06:15:05.383Z [WARNING]: - Initializing your environment: prg
2023-07-12T06:15:05.414Z [WARNING]: ✔ Initialized provider successfully.
2023-07-12T06:15:05.469Z [WARNING]: ✖ There was an error initializing your environment.
2023-07-12T06:15:05.469Z [INFO]: 🛑 This environment is missing some parameter values.
2023-07-12T06:15:05.469Z [INFO]: [variable1,variable2] do not have values.
Resolution: Run 'amplify push' interactively to specify values.
Alternatively, manually add values in SSM ParameterStore for the following parameter names:
/amplify/d1d2qz3ywham00/prg/AMPLIFY_function_reactmultipage5cc10a9d_variable1
/amplify/d1d2qz3ywham00/prg/AMPLIFY_function_reactmultipage5cc10a9d_variable2
Learn more at: https://docs.amplify.aws/cli/reference/ssm-parameter-store/#manually-creating-parameters
2023-07-12T06:15:05.478Z [INFO]:
2023-07-12T06:15:05.479Z [INFO]: Session Identifier: 448cca09-c44d-4a5e-ab29-61f47afa8a5e
2023-07-12T06:15:05.495Z [ERROR]: !!! Build failed
2023-07-12T06:15:05.495Z [ERROR]: !!! Non-Zero Exit Code detected
2023-07-12T06:15:05.496Z [INFO]: # Starting environment caching...
2023-07-12T06:15:05.496Z [INFO]: # Environment caching completed
Terminating logging...
```
Amplify.yml
```
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```
Another follow-up query as the random name creates confusion in understanding that which PR is related to which branch -
- How we can specify the name of backend environment which is initialised during build or is there any way using which we know that random name before deployment.
- Would it be possible if we can replace the random backend environment with the name of git branch from which PR was raised.
_Originally posted by @anivarsh in https://github.com/aws-amplify/amplify-cli/issues/12644#issuecomment-1636370495_
Contributor guide
Assessment
This issue has not been assessed yet.