amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

lastPushTimeStamp issue when adding API

Open cdellinger opened this issue 6 years ago • 19 comments

Describe the bug Whenever I try adding a REST API to a brand new React project via the AWS-CLI I successfully walk through the questions to create the API but when I execute an "amplify push" I receive a message that says "Successfully pulled backend environment dev from the cloud." and then it gives an error of "An error occurred during the push operation: Cannot read property 'lastPushTimeStamp' of undefined".

After getting into this error state if I try to run "amplify status" I get the following error:

Current Environment: dev

Cannot read property 'lastPushTimeStamp' of undefined
TypeError: Cannot read property 'lastPushTimeStamp' of undefined
    at getResourcesToBeCreated (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:122:76)
    at getResourceStatus (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:205:32)
    at AmplifyToolkit.showResourceTable [as _showResourceTable] (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:232:102)
    at Object.exports.run (/usr/local/lib/node_modules/@aws-amplify/cli/lib/commands/status.js:5:27)
    at Object.executeAmplifyCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/index.js:166:29)
    at async executePluginModuleCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:153:5)
    at async Object.executeCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:34:9)
    at async Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/lib/index.js:94:9)

If try to remove the api via "amplify remove api", the cli walks me through the steps but throws the following error when I verify that I want to remove the specified api.

TypeError: Cannot read property 'lastPushTimeStamp' of undefined
    at getResourcesToBeCreated (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:122:76)
    at AmplifyToolkit.getResourceStatus [as _getResourceStatus] (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:205:32)
    at deleteResourceFiles (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/remove-resource.js:114:56)
    at AmplifyToolkit.removeResource [as _removeResource] (/usr/local/lib/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/remove-resource.js:101:16)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.executeAmplifyCommand (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/lib/index.js:147:5)
    at async executePluginModuleCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:153:5)
    at async Object.executeCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:34:9)
    at async Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/lib/index.js:94:9)
There was an error removing the api resource

Amplify CLI Version 4.27.2

To Reproduce Create REST API then run amplify push

Expected behavior Be able to push the newly defined API to AWS

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: 12.18.3

Additional context

cdellinger avatar Aug 17 '20 20:08 cdellinger

Trying to debug the code, it looks like when I execute an "amplify status" it fails when trying to process the API Gateway resource. Looking in amplify-meta.json file in the /amplify/backend directory I see a property named lastPushTimeStamp for other resources that amplify has helped me create (auth, storage) but there is not a lastPushTimeStamp property for the entry for the "function" or "api" that got created in this file when I created the API.

cdellinger avatar Aug 17 '20 20:08 cdellinger

Hi @cdellinger could you provide more details around how you initialized the project? Did you just run amplify init and follow the walkthrough? Also, did you have other resources configured in the project before that you then deleted?

edwardfoyle avatar Aug 18 '20 01:08 edwardfoyle

The project was created with amplify init. The first resource that was added was auth with cognito, I was able to do a push and run successfully. I then added the api and failed as mentioned above. I found a similar issue from back in April which recommended doing a "amplify pull dev --restore", it was the only thing I can do to back out the API problem. After I did that I added storage (another issue here in this forum said that helped someone with a similar problem) in the form of a dynamodb table. That action completed successfully and I was able to do a successful push. I then tried adding the API again as described above with the same result.

cdellinger avatar Aug 18 '20 02:08 cdellinger

I'm having the same experience. Same amplify version (4.27.2).

brooksidesw avatar Aug 19 '20 14:08 brooksidesw

Hi @cdellinger and @brooksidesw

From the error it seems , you have some resources which depends on another resource. Did you selected a resource which depends on the lambda function in the workflow of adding REST api?

akshbhu avatar Aug 25 '20 18:08 akshbhu

I cannot say I am aware of selecting a resource that depends on the lambda. Would the DynamoDB table created by the amplify script place a dependency on the lambda?

brooksidesw avatar Aug 26 '20 19:08 brooksidesw

Hi @brooksidesw

It will only create the dependency if you have selected the option in the workflow while adding REST API. Can you elaborate more on the amplify script that you mentioned?

akshbhu avatar Aug 26 '20 21:08 akshbhu

For me I see this error at times when I try creating resources with dependencies and also at times without dependencies, I can't seem to determine the pattern.

cdellinger avatar Aug 29 '20 12:08 cdellinger

I just replicated it this morning here are two screen prints that show what I did.

image

image

cdellinger avatar Aug 29 '20 12:08 cdellinger

Hi @cdellinger , @brooksidesw

Thanks for reporting this. I have made the fix in above PR.

akshbhu avatar Aug 31 '20 08:08 akshbhu

It looks like this is still happening to me and i have version 4.29.0

dwardu89 avatar Sep 05 '20 20:09 dwardu89

It looks like this is still happening on version 4.29.1

mmendonca3 avatar Sep 11 '20 01:09 mmendonca3

Hi @mmendonca3 and @dwardu89

Can you post your amplify-meta.json file after redacting secret information from it?

akshbhu avatar Sep 11 '20 02:09 akshbhu

I'm also experiencing issues with having an API defined that is dependent on a Lambda function. By manually removing sections on my amplify-meta.json file, I've narrowed the issue down to the following section:

{ "function": { "widgets": { "build": true, "providerPlugin": "awscloudformation", "service": "Lambda", "dependsOn": [] } }, "api": { "widgets": { "service": "API Gateway", "providerPlugin": "awscloudformation", "dependsOn": [ { "category": "function", "resourceName": "get-widgets", "attributes": [ "Name", "Arn" ] } ] } } }

@akshbhu - please let me know what else I could provide to help with this issue. I'm using version 4.29.2 of the CLI.

zachwaltz avatar Sep 18 '20 13:09 zachwaltz

I am getting this error too, when trying to 'amplify push' after adding api locally. Just before that I deleted one api and a function and I have used some names for resources which were previously used. Not sure if it has anything to do with error. My amplify version is 4.27.0

Anyone got any workaround?

yogimishra avatar Sep 21 '20 20:09 yogimishra

Hi @zachwaltz

I think this might be because you added the api and function before fix was released. Your function resourceName(widgets) is different from function resourcename present in api depends on (get-widgets). Can you try this and check if it is working:

{ 
    "function": { 
        "widgets": { 
            "build": true, 
            "providerPlugin": "awscloudformation", 
            "service": "Lambda", 
            "dependsOn": [] 
        }, 
        "api": { 
            "widgets": { 
                "service": "API Gateway", 
                "providerPlugin": "awscloudformation", 
                "dependsOn": [
                     { 
                         "category": "function", 
                         "resourceName": "get-widgets", 
                         "attributes": [ "Name", "Arn" ] 
                     } 
                ]
            } 
        } 
    } 
}

Let me know if this works?

@yogimishra You can also check in amplify-meta.json file , function resourceName should be similar to function resourceName in api depends on. If problem still occurs ,can you post your amplify-meta.json file after redacting secret information from it?

akshbhu avatar Sep 21 '20 21:09 akshbhu

@akshbhu Thanks a lot for the help.

Yes, for me this was the issue. My function resourceName was different than the function resourceName in api. Once I made both same, it started working.

So for future, is that mean, I need to keep the function resource name and lambda function name same? Also, could you please let me know how to update my amplify cli without reinstalling everything.

yogimishra avatar Sep 22 '20 13:09 yogimishra

? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react-native
? Source Directory Path:  src
? Distribution Directory Path: /
? Build Command:  npm run-script build
? Start Command: npm run-script start
? Do you plan on modifying this backend? Yes
✔ Successfully pulled backend environment dev from the cloud.
✖ There was an error initializing your environment.
Failed to pull the backend.
Cannot read property 'lastPushTimeStamp' of undefined
TypeError: Cannot read property 'lastPushTimeStamp' of undefined
    at getResourcesToBeCreated (/snapshot/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:124:77)
    at AmplifyToolkit.getResourceStatus [as _getResourceStatus] (/snapshot/node_modules/@aws-amplify/cli/lib/extensions/amplify-helpers/resource-status.js:263:32)
    at initEnv (/snapshot/node_modules/amplify-category-function/lib/index.js:112:110)
    at /snapshot/node_modules/@aws-amplify/cli/lib/initialize-env.js:38:64
    at /snapshot/node_modules/promise-sequential/index.js:16:18
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

I got this error when trying to pull from amplify

bernardnongpoh avatar Mar 02 '21 02:03 bernardnongpoh

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 01:05 github-actions[bot]