funtyper
funtyper

Reputation: 203

AWS CDK - Unable to increase Lambda timeout

My lambda function needs more time to execute so when I increase it

    const postReader_NewPost = new lambda.Function(this, 'PostReader_NewPost', {
      code: lambda.Code.fromAsset('lambda'),
      runtime: lambda.Runtime.PYTHON_2_7,
      handler: 'PostReader_NewPost.handler',
      timeout: Duration.seconds(300),
      description: "",
      environment: {
        "DB_TABLE_NAME": table.tableName,
        "SNS_TOPIC": topic.topicArn
      },
      role:role,
    });

I get the following error

Type 'import("c:/Users/myusername/Documents/GitHub/cdk_polly_website/node_modules/@aws-cdk/core/lib/duration").Duration' is not assignable to type 'import("c:/Users/myusername/Documents/GitHub/cdk_polly_website/node_modules/@aws-cdk/aws-dynamodb/node_modules/@aws-cdk/core/lib/duration").Duration'.
  Types have separate declarations of a private property 'amount'.ts(2322)
function.d.ts(68, 14): The expected type comes from property 'timeout' which is declared here on type 'FunctionProps'

I've declared on top of the class

import { Duration } from '@aws-cdk/core';

My package.json has following dependencies

"dependencies": {
    "@aws-cdk/aws-apigateway": "^1.88.0",
    "@aws-cdk/aws-dynamodb": "^1.88.0",
    "@aws-cdk/aws-iam": "^1.88.0",
    "@aws-cdk/aws-lambda": "^1.88.0",
    "@aws-cdk/aws-lambda-event-sources": "^1.88.0",
    "@aws-cdk/aws-sns": "^1.88.0",
    "@aws-cdk/aws-sns-subscriptions": "^1.88.0",
    "@aws-cdk/core": "1.88.0",
    "source-map-support": "^0.5.16"
  }

Appreciate help. Thanks

Upvotes: 5

Views: 10992

Answers (4)

Albert
Albert

Reputation: 131

You are using different versions of @ aws-cdk / core and @ aws-cdk / aws-lambda.

Upvotes: 0

Satakshi Pandey
Satakshi Pandey

Reputation: 432

import {Duration} from "@aws-cdk/core";

Add timeout variable in api.constructs file

timeout:Duration.seconds(30)

Upvotes: -1

funtyper
funtyper

Reputation: 203

Through npm ls I found that I don't have same version of different aws cdk libraries

npm ls
[email protected] C:\Users\amuham210\Documents\GitHub\cdk_polly_website
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @aws-cdk/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

so I explicitly installed version to make it same

npm install @aws-cdk/[email protected]

This fixed the problem.

Upvotes: 2

urirot
urirot

Reputation: 399

This way always works for me: aws-examples

Import core and then use Duration as core.Duration.

I'm not sure if it will help, but it looks like your core import is being taken from aws-dynamodb this way.

If this solves it, I'd like to investigate why.

Upvotes: 5

Related Questions