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

REST API call runs multiple times

Open GenGraphic opened this issue 3 weeks ago • 4 comments

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

REST API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

# Put output below this line
  System:
    OS: Windows 11 10.0.26100
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 3.91 GB / 15.95 GB
  Binaries:
    Node: 20.19.4 - C:\nvm4w\nodejs\node.EXE
    Yarn: 1.22.22 - C:\nvm4w\nodejs\yarn.CMD
    npm: 10.8.2 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Chrome: 142.0.7444.176
    Edge: Chromium (140.0.3485.54)
  npmPackages:
    @aws-amplify/react-native: ^1.3.0 => 1.3.0 
    @aws-amplify/rtn-web-browser: ^1.0.29 => 1.2.0 
    @aws-amplify/storage: ^6.6.2 => 6.10.1 
    @aws-amplify/storage/internals:  undefined ()
    @aws-amplify/storage/s3:  undefined ()
    @aws-amplify/storage/s3/server:  undefined ()
    @aws-amplify/storage/server:  undefined ()
    @aws-amplify/ui-react-native: ^2.2.0 => 2.6.3 
    @aws-sdk/client-sns: ^3.650.0 => 3.930.0 
    @babel/core: ^7.25.2 => 7.28.5 
    @gorhom/bottom-sheet: ^5.2.6 => 5.2.6 
    @jsamr/counter-style: ^2.0.2 => 2.0.2 
    @jsamr/react-native-li: ^2.3.1 => 2.3.1 
    @react-native-async-storage/async-storage: ^2.2.0 => 2.2.0 
    @react-native-community/checkbox: ^0.5.17 => 0.5.20 
    @react-native-community/cli: latest => 20.0.2 
    @react-native-community/netinfo: ^11.4.1 => 11.4.1 
    @react-native-masked-view/masked-view: 0.2.9 => 0.2.9 
    @react-native-picker/picker: 2.11.1 => 2.11.1 
    @react-navigation/bottom-tabs: ^7.2.0 => 7.8.4 
    @react-navigation/drawer: ^7.1.1 => 7.7.2 
    @react-navigation/native: ^7.0.14 => 7.1.19 
    @react-navigation/native-stack: ^7.2.0 => 7.6.2 
    @react-navigation/stack: ^7.1.1 => 7.6.3 
    @reduxjs/toolkit: ^2.6.1 => 2.10.1
    @reduxjs/toolkit-query:  1.0.0
    @reduxjs/toolkit-query-react:  1.0.0
    @reduxjs/toolkit-react:  1.0.0
    @types/react: ~19.1.10 => 19.1.17
    aws-amplify: ^6.15.8 => 6.15.8
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/adapter-core/internals:  undefined ()       
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()   
    aws-amplify/analytics/personalize:  undefined ()        
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/internals:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()   
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()    
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()  
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    aws-sdk: ^2.1659.0 => 2.1692.0
    axios: ^1.7.2 => 1.13.2
    buffer: ^6.0.3 => 6.0.3 (4.9.2, 5.7.1, 5.0.8)
    crypto-js: ^4.2.0 => 4.2.0
    expo: ^54.0.13 => 54.0.23
    expo-build-properties: ~1.0.9 => 1.0.9
    expo-checkbox: ~5.0.7 => 5.0.7
    expo-constants: ~18.0.9 => 18.0.10
    expo-dev-client: ~6.0.15 => 6.0.17
    expo-file-system: ~19.0.17 => 19.0.17
    expo-font: ~14.0.9 => 14.0.9
    expo-image-picker: ~17.0.8 => 17.0.8
    expo-linking: ~8.0.8 => 8.0.8
    expo-local-authentication: ~17.0.7 => 17.0.7
    expo-sharing: ~14.0.7 => 14.0.7
    expo-splash-screen: ~31.0.10 => 31.0.10
    expo-status-bar: ~3.0.8 => 3.0.8
    expo-updates: ~29.0.12 => 29.0.12
    he: ^1.2.0 => 1.2.0
    ini: ^1.3.5 => 1.3.8
    inquirer: ^6.5.1 => 6.5.2
    node-fetch: ^3.3.2 => 3.3.2
    patch-package: ^8.0.0 => 8.0.1
    pdf-lib: ^1.17.1 => 1.17.1
    postinstall-postinstall: ^2.1.0 => 2.1.0
    react: 19.1.0 => 19.1.0 (19.2.0-canary-5252281c-20250408)
    react-currency-input-field: ^3.10.0 => 3.10.0
    react-dom: 19.1.0 => 19.1.0 (19.2.0-canary-5252281c-20250408)
    react-native: 0.81.4 => 0.81.4
    react-native-blob-util: ^0.24.4 => 0.24.4
    react-native-confirmation-code-field: ^7.4.0 => 7.6.1   
    react-native-currency-input: ^1.1.1 => 1.1.1
    react-native-dotenv: ^3.4.11 => 3.4.11
    react-native-dropdown-picker: ^5.4.6 => 5.4.6
    react-native-element-dropdown: ^2.12.1 => 2.12.4        
    react-native-fs: ^2.20.0 => 2.20.0
    react-native-gesture-handler: ~2.28.0 => 2.28.0
    react-native-get-random-values: ~1.11.0 => 1.11.0       
    react-native-gifted-charts: ^1.4.64 => 1.4.65
    react-native-google-places-autocomplete: ^2.5.7 => 2.5.7

    react-native-google-places-textinput: ^0.9.1 => 0.9.1   
    react-native-linear-gradient: ^2.8.3 => 2.8.3
    react-native-pager-view: 6.9.1 => 6.9.1
    react-native-pdf: ^7.0.0 => 7.0.3
    react-native-pdf-renderer: ^1.3.2 => 1.6.0
    react-native-phone-input: ^1.3.7 => 1.3.7
    react-native-popover-view: ^5.1.8 => 5.1.9
    react-native-progress: ^5.0.1 => 5.0.1
    react-native-radio-buttons-group: ^3.1.0 => 3.1.0       
    react-native-reanimated: ~4.1.1 => 4.1.5
    react-native-reanimated-carousel: ^3.5.1 => 3.5.1       
    react-native-responsive-linechart: ^5.7.1 => 5.7.1      
    react-native-safe-area-context: ~5.6.0 => 5.6.2
    react-native-screens: ~4.16.0 => 4.16.0
    react-native-select-multiple: ^2.1.0 => 2.1.0
    react-native-share: ^11.0.4 => 11.1.0
    react-native-skeleton-placeholder: ^5.2.4 => 5.2.4      
    react-native-snap-carousel: ^1.3.1 => 1.6.1
    react-native-svg: ^15.14.0 => 15.15.0
    react-native-tab-view: ^3.5.2 => 3.5.2
    react-native-table-component: ^1.2.2 => 1.2.2
    react-native-toast-message: ^2.2.0 => 2.3.3
    react-native-unordered-list: ^1.0.4 => 1.0.4
    react-native-uuid: ^2.0.2 => 2.0.3
    react-native-vector-icons: ^10.2.0 => 10.3.0
    react-native-virtualized-view: ^1.0.0 => 1.0.0
    react-native-webview: 13.15.0 => 13.15.0
    react-native-worklets: 0.5.1 => 0.5.1
    react-native-xml2js: ^1.0.3 => 1.0.3
    react-redux: ^9.2.0 => 9.2.0
    redux-persist: ^6.0.0 => 6.0.0
    redux-persist/integration/react:  undefined ()
    sharp: ^0.34.1 => 0.34.5
    soap: ^1.0.3 => 1.6.0
    stream: ^0.0.2 => 0.0.2
    typescript: ^5.8.2 => 5.9.3
    util: ^0.12.5 => 0.12.5
    uuid: ^9.0.1 => 9.0.1 (11.1.0, 8.0.0, 10.0.0, 7.0.3)    
    xml2js: ^0.6.2 => 0.6.2 (0.6.0)
    xmldom: ^0.6.0 => 0.6.0
  npmGlobalPackages:
    @aws-amplify/cli: 14.2.1
    appwrite-cli: 10.2.3
    aws: 0.0.3-2
    corepack: 0.32.0
    eas-cli: 16.24.1
    npm: 10.8.2
    yarn: 1.22.22

Describe the bug

I have noticed that some of my API are beeing triggered multiple times. I know that when it fails it trying again, but in my case it runs 2-3 times even if it succed.

Expected behavior

Making a post call should trigger the function only once. But in CloudWatch i can see how the function runs 2 -3 times randomly.

Image

Reproduction steps

npm start

Code Snippet

// Put your code below this line.
const uploadPDF = async (actionId: string, pdfBase64: string) => {
        try {
            const restOperation = post({
                apiName: 'webIdActionIdGen',
                path: '/upload-pdf',
                options: {
                    body: {
                        actionId,
                        pdfBase64,
                    },
                },
            });

            const {body} = await restOperation.response;
            const response = await body.json();

            console.log(response)
        }catch (err: any) {
            console.log("Error uploading PDF:", err);
        }
    };

Log output

Image
// Put your logs below this line


aws-exports.js

/* eslint-disable */ // WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = { "aws_project_region": "eu-central-1", "aws_cloud_logic_custom": [ { "name": "clientNrAPI", "endpoint": "", "region": "eu-central-1" }, { "name": "dailyDataColectorApi", "endpoint": "", "region": "eu-central-1" }, { "name": "dashOTP", "endpoint": "", "region": "eu-central-1" }, { "name": "errorNotify", "endpoint": "", "region": "eu-central-1" }, { "name": "etfHistoryDailyCollector", "endpoint": "", "region": "eu-central-1" }, { "name": "getContractAlTableData", "endpoint": "", "region": "eu-central-1" }, { "name": "getContractPDF", "endpoint": "", "region": "eu-central-1" }, { "name": "newsletterSubscribersManager", "endpoint": ", "region": "eu-central-1" }, { "name": "pdfEmailSender", "endpoint": "", "region": "eu-central-1" }, { "name": "phoneNumberValidator", "endpoint": "", "region": "eu-central-1" }, { "name": "storeMarketingSubscribers", "endpoint": "", "region": "eu-central-1" }, { "name": "storeSecreteKeyApi", "endpoint": "", "region": "eu-central-1" }, { "name": "supportEmailAPI", "endpoint": "", "region": "eu-central-1" }, { "name": "webIdActionIdGen", "endpoint": "", "region": "eu-central-1" }, { "name": "webIdResponseHandler", "endpoint": "", "region": "eu-central-1" }, { "name": "getPartnerData", "endpoint": "", "region": "eu-central-1" } ], "aws_appsync_graphqlEndpoint": "", "aws_appsync_region": "", "aws_appsync_authenticationType": "", "aws_appsync_apiKey": "", "aws_cognito_identity_pool_id": "", "aws_cognito_region": "", "aws_user_pools_id": "", "aws_user_pools_web_client_id": "", "oauth": {}, "aws_cognito_username_attributes": [ "EMAIL" ], "aws_cognito_social_providers": [], "aws_cognito_signup_attributes": [], "aws_cognito_mfa_configuration": "OFF", "aws_cognito_mfa_types": [ "SMS" ], "aws_cognito_password_protection_settings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "aws_cognito_verification_mechanisms": [ "EMAIL" ], "aws_dynamodb_all_tables_region": "eu-central-1", "aws_dynamodb_table_schemas": [ { "tableName": "BlogPost-prod", "region": "eu-central-1" }, { "tableName": "ClientCounterTable-prod", "region": "eu-central-1" }, { "tableName": "ContractsAL-prod", "region": "eu-central-1" }, { "tableName": "SecreteKeys-prod", "region": "eu-central-1" }, { "tableName": "Transactions-prod", "region": "eu-central-1" } ], "aws_user_files_s3_bucket": "", "aws_user_files_s3_bucket_region": "eu-central-1" };

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

Iphone 12, Iphone SE, Iphone XS Max, PIxel 9 PRO

Mobile Operating System

IOS 26, IOS 16, Android 16

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

GenGraphic avatar Nov 26 '25 09:11 GenGraphic

Hi @GenGraphic,

Thank you for creating this issue. We will look into that and get back to you as soon as we have more information or need additional details.

soberm avatar Nov 27 '25 15:11 soberm

Hi @GenGraphic,

Unfortunately, I haven't been able to reproduce the behavior you're experiencing. To help us diagnose this further, could you please provide some additional information?

  • Are you experiencing any network instability or switching between networks when this occurs?
  • What's the time gap between the duplicate Lambda invocations? Are the calls happening simultaneously or with fixed delays?
  • What HTTP status code is the Lambda returning? (200, 201, etc.)
  • Are there any errors in the client-side console/logs when this happens?
  • Does the client receive the response successfully before the duplicates occur?
  • Does this happen with all of your REST APIs, or just specific ones?

You can also try to disable the retries to see if this is causing multiple calls:

const restOperation = post({
  apiName: 'webIdActionIdGen',
  path: '/upload-pdf',
  options: {
    body: { actionId, pdfBase64 },
    // Disable automatic retries
    retryStrategy: { strategy: 'no-retry' }
  }
});

Amplify REST API has a default retry mechanism (up to 3 attempts) that triggers on the following errors:

  • Network errors
  • 5xx server errors
  • 429 throttling errors
  • Timeout errors

In any case it would be very helpful if you can provide us with a minimal reproduction sample to help us with the investigation.

Thanks!

soberm avatar Nov 28 '25 10:11 soberm

Are you experiencing any network instability or switching between networks when this occurs? No.

What's the time gap between the duplicate Lambda invocations? Are the calls happening simultaneously or with fixed delays? they are concurent, one right after another. But i can'notice it in my app, becasue the api give the response back only after all 3 finishes.

What HTTP status code is the Lambda returning? (200, 201, etc.) 200

Are there any errors in the client-side console/logs when this happens? Not in every case. We do have one that can be ignored in this exemple i gave. But we saw this happening multiple times.

Does the client receive the response successfully before the duplicates occur? No, i have to wait for all of them to finish

Does this happen with all of your REST APIs, or just specific ones? Some of them, not all. And not allways, there are times when i see in cloudwatch that it runs only once.

What i assumed is that the requests are not duplicates, based on the request id beeing different on each try. But the API is calling the function 3 times.

GenGraphic avatar Nov 29 '25 03:11 GenGraphic

Hello @GenGraphic ,

Have you tried explicitly disabling the retry as suggested by @soberm ?

const restOperation = post({
  apiName: 'webIdActionIdGen',
  path: '/upload-pdf',
  options: {
    body: { actionId, pdfBase64 },
    // Disable automatic retries
    retryStrategy: { strategy: 'no-retry' }
  }
});

Without explicitly setting the retryStrategy to 'no-retry' , by default the request will be retried.

To add more context, if the Lambda returns 200 but there's a network issue, timeout, or connection problem on the client side before the response is fully received, Amplify will retry the request. If the API is not idempotent, we would recommend disabling the retry.

Let us know if this resolves your issue.

Simone319 avatar Dec 02 '25 14:12 Simone319