0
votes

I am building a cdk script for some lambdas and gateways. I am busy packing up my layers, but get the error staging.relativeStagedPath is not a function.

The code that sets it off is this, specifialy the Code.from_asset line.

self.sqlalchemy_layer = LayerVersion(
        self,
        "Sqlalchemy-Lambda-Layer",
        compatible_runtimes=[Runtime.PYTHON_3_8],
        code=Code.from_asset("./src/layers/sqlalchemy-layer.zip"),
    )

I confirmed that the code does exist and I get a 'file not found error' if I mess around with the location of my layer.

I also confirmed that the from_asset function does take a string pointing towards a zip file.

 def from_asset(
    cls,
    path: builtins.str,
    *,
   ...
) -> "AssetCode":
    """Loads the function code from a local disk path.

    :param path: Either a directory with the Lambda code bundle or a .zip file.

Changing the code to point to a directory with the code bundled instead of a zip gives the same issue.

Does anyone know why I am getting this error?

2
have you fixed this issue yet?Thanh Nguyen Van

2 Answers

1
votes

I managed to "solve" this. I copied all of my code bit by bit to a previously setup CDK test environment, with the hope that one of the lines will show me where the system is breaking, or at least guide me. Hoever, since everything just kept on working, I decided to rebuild a new CDK from scratch, and then copy my lambdas and layers over to the deploy directories. And this time, everything just worked. So I do not know what went wrong, but I am happy that a rebuilt solved my problem.

0
votes

I have been struggling with this jsii error as well as another jsii error. Finally have a workaround that worked for me.

Workaround 1: replace jsii 1.14.x distro in site-packages with 1.12 or 1.13 distro. After swapping out 1.14 for 1.12 or 1.13, errors stop.

IF you are using Windows to run CDK, then there is a bug in jsii documented by AWS CDK group. I reported it to aws-cdk. They reproduced the bug and created a bug report at nodejs. This bug report has links to the other bug reports. https://github.com/aws/aws-cdk/issues/11314

Workaround 2: move dev environment off Windows and onto linux or mac

My related stackoverflow question: Returns JSII error when attempting to create empty stack with python AWS CDK