Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
Describe the bug
Using Amplify's env checkout, pull or add command loses dependsOn array items.
Consider the use case where your Lambda function needs some information about your Cognito deployment, for this example I picked UserPoolId.
To achieve this you add Cognito's UserPoolId to your Lambda's dependsOn property in amplify-meta.json, and then you reference that in your Lambda's CloudFormation template file as an environment variable so that you can access it in your Lambda function.
Everything works well until you checkout, add or pull an environment which removes your dependsOn item from amplify-meta.json and causes reference errors when pushing:
UPDATE_ROLLBACK_IN_PROGRESS dependsonbug-20190403155855 AWS::CloudFormation::Stack Wed Apr 03 2019 17:33:02 GMT+1100 (Australian Eastern Daylight Time) The following resource(s) failed to update: [functiondependsonbuge1b198d9].
UPDATE_FAILED functiondependsonbuge1b198d9 AWS::CloudFormation::Stack Wed Apr 03 2019 17:33:00 GMT+1100 (Australian Eastern Daylight Time) Parameters: [authcognitoa6fe1306UserPoolId] do not exist in the template
To Reproduce
Steps to reproduce the behavior:
Losing data to env add:
Losing data to pull:
Losing data to checkout:
Expected behavior
Changes to dependsOn for resources inside amplify-meta.json should be saved to the environment when 'amplify push' is used on that environment.
OR
There should be a way to configure dependencies between CloudFormation template files that MultiEnv supports
Desktop (please complete the following information):
Steps taken to create the test workspace for reproducing the bug
==== Make a new amplify environment ====
amplify init
? Enter a name for the project dependsOnBug
? Enter a name for the environment test
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
? What javascript framework are you using react-native
? Source Directory Path: src
? Distribution Directory Path: dist
? Build Command: npm run-script build
? Start Command: npm run-script start
==== Add an Cognito ====
amplify add auth
Using service: Cognito, provided by: awscloudformation
The current configured provider is Amazon Cognito.
Do you want to use the default authentication and security configuration? Yes, use the default configuration.
==== Add an API & Storage ====
amplify add api
? Please select from one of the below mentioned services REST
? Provide a friendly name for your resource to be used as a label for this category in the project: apicaed5a58
? Provide a path (e.g., /items) /items
? Choose a Lambda source Create a new Lambda function
? Provide a friendly name for your resource to be used as a label for this category in the project: dependsonbuge1b198d9
? Provide the AWS Lambda function name: dependsonbuge1b198d9
? Choose the function template that you want to use: CRUD function for Amazon DynamoDB table (Integration with Amazon API Gateway and Amazon DynamoDB)
? Please provide a friendly name for your resource that will be used to label this category in the project: dynamo542a04ca
? Please provide table name: dynamo542a04ca
? What would you like to name this column: test
? Please choose the data type: string
? Would you like to add another column? No
? Please choose partition key for the table: test
? Do you want to add global secondary indexes to your table? No
? Do you want to edit the local lambda function now? No
? Restrict API access No
? Do you want to add another path? No
==== Add some parameters for testing ====
Set dependsonbuge1b198d9-cloudformation-template.json Parameters to
"Parameters": {
"env": {
"Type": "String"
},
"storagedynamo542a04caName": {
"Type": "String",
"Default": "storagedynamo542a04caName"
},
"storagedynamo542a04caArn": {
"Type": "String",
"Default": "storagedynamo542a04caArn"
},
"authcognitoa6fe1306UserPoolId": {
"Type": "String",
"Default": "authcognitoa6fe1306UserPoolId"
}
}
Set dependsonbuge1b198d9-cloudformation-template.json Resources.LambdaFunction.Properties.Environment to
"Environment": {
"Variables": {
"ENV": {
"Ref": "env"
},
"UserPoolId": {
Ref": "authcognitoa6fe1306UserPoolId"
}
}
}
Set amplify-meta.json function.dependsonbuge1b198d9.dependsOn[] to
"dependsOn": [
{
"category": "storage",
"resourceName": "dynamo542a04ca",
"attributes": [
"Name",
"Arn"
]
},
{
"category": "auth",
"resourceName": "cognitoa6fe1306",
"attributes": [
"UserPoolId"
]
}
]
==== Push to test environment ====
amplify push
@luisvsm You would have to also modify your amplify/backend-config.json file to persist this dependsOn relations to be persisted across multiple environments.
Thanks @kaustavghosh06, just tested and that's sorted my issue.
Most helpful comment
@luisvsm You would have to also modify your amplify/backend-config.json file to persist this dependsOn relations to be persisted across multiple environments.