question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing nuGet packages after deploying Web Serverless with CDK in C#

See original GitHub issue

I created a single web serverless application using the default template for the AWS toolkit. I created a CDK project to deploy it with a simple lambda function and the LambdaRestApi.

When deploying with cdk everything goes fine, the asset file is created and the stack deploys without any problem.

When I try to browse the url returned in output, I get {“message”: “Internal server error”}. Checking the logs at CloudWatch the error is totally unexpected:

`

Error:
An assembly specified in the application dependencies manifest (CdkMissingLib.deps.json) was not found:
package: 'Amazon.Lambda.APIGatewayEvents', version: '1.2.0'
path: 'lib/netstandard2.0/Amazon.Lambda.APIGatewayEvents.dll'
START RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a Version: $LATEST
Failed to execute the Lambda function. The dotnet CLI failed to start with the provided deployment package. Please check CloudWatch logs for this Lambda function to get detailed information about this failure.: LambdaException

END RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a
REPORT RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a Duration: 457.96 ms Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 64 MB Init Duration: 239.59 ms

`

The package it’s complaining is not even used in my solution. Furthermore, the solution where I found this problem was complaining about another nuget package “AWSSDK.Core” that WAS referenced in the solution…

Reproduction Steps

This is how I define the stack for CDK:

public class CdkMissingLibInfraStack : Stack
  {
      public CdkMissingLibInfraStack(Construct parent, string id, IStackProps props) : base(parent, id, props)
      {


          var lambdaFunction = new Function(this, "webapi-function",
              new FunctionProps
              {
                  Code = Code.FromAsset(@"C:\Users\joanv\Source\Repos\CdkMissingLib\CdkMissingLib\bin\Debug\netcoreapp2.1"),
                  Handler = "CdkMissingLib::CdkMissingLib.LambdaEntryPoint::FunctionHandlerAsync",
                  Runtime = Runtime.DOTNET_CORE_2_1,
                  Timeout = Duration.Seconds(30),
                  MemorySize = 128
              }
          );

          var api = new LambdaRestApi(this, "webapi-function-api", new LambdaRestApiProps
          {
              Handler = lambdaFunction
          });

      }
  }

Error Log

Error: An assembly specified in the application dependencies manifest (CdkMissingLib.deps.json) was not found: package: ‘Amazon.Lambda.APIGatewayEvents’, version: ‘1.2.0’ path: ‘lib/netstandard2.0/Amazon.Lambda.APIGatewayEvents.dll’ START RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a Version: $LATEST Failed to execute the Lambda function. The dotnet CLI failed to start with the provided deployment package. Please check CloudWatch logs for this Lambda function to get detailed information about this failure.: LambdaException

END RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a REPORT RequestId: 938d4091-a8d2-4e5c-a4eb-3ffbb69b090a Duration: 457.96 ms Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 64 MB Init Duration: 239.59 ms

Environment

  • CLI Version : 11.12.0 (build 923055e)
  • Framework Version: 2.1
  • OS : Windows
  • Language : C# .Net Core

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
rix0rrrcommented, Oct 8, 2019

Also please be aware you will need to build your .NET project before running the CDK deploy on it. CDK will not build for you.

0reactions
LechuckThePiratecommented, Oct 8, 2019

Fixed guys… thanks for your help… here’s the final “deploy.ps1” script I created … it works like a charm:

# Input Parameters
param (
    $localFolder = "C:\Users\joanv\Source\Repos\CdkMissingLib"
);


# Helpers
function Write-ColorOutput($ForegroundColor)
{
    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

    # set the new color
    $host.UI.RawUI.ForegroundColor = $ForegroundColor

    # output
    if ($args) {
        Write-Output $args
    }
    else {
        $input | Write-Output
    }

    # restore the original color
    $host.UI.RawUI.ForegroundColor = $fc
}

# Building & Packaging
Write-ColorOutput "cyan" "Building Solution..."
Set-Location $localFolder
dotnet build .\CdkMissingLib.sln -c Release

if ($?) 
{
    Write-ColorOutput "cyan" "  >> Packaging artifacts..."
    Set-Location .\CdkMissingLib
    dotnet lambda package -f netcoreapp2.1 -c Release 
}

Set-Location $localFolder

if ($?) {
    # Deploying to AWS
    Write-ColorOutput "cyan" "Deploying to AWS..."
    cdk deploy 
}

if ($?) {
    # End
    Write-ColorOutput "green" "Done!"
}

if (!$?) {
    Write-ColorOutput "red" "There was an error in the process ..."
}
Set-Location $localFolder

In my CDK project I just changed the Code.FromAsset to point to the packaged ZIP:

image

This did the trick… the website is now working.

Going to apply this to the real project now… Thanks again for your help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with the AWS CDK in C# - AWS Cloud Development ...
Visual Studio's NuGet tools are accessible from Tools > NuGet Package Manager > Manage NuGet Packages for Solution. Use the Browse tab to...
Read more >
NuGet Packages are missing - visual studio - Stack Overflow
My NuGet version is 3.1.6. This problem is happening only in my C# Web API/MVC project. I am getting the below error: This...
Read more >
Creating an AWS Serverless C# DotNet Application (S3 ...
These will all be deployed using Cloud Development Kit(CDK) in C#. ... Resolve the missing references by managing the nuget packages.
Read more >
AWS DotNet Lambda Functions powered by AWS Graviton2 ...
Right click in the Solution Explorer and select “Manage Nuget Packages for Solution…”. Follow the same process as you did for the Amazon.CDK...
Read more >
Developing on AWS with C# - Awsstatic
NET developer to bookmark this website since it has a curated view ... Install one of the over 600+ packages available for AWS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found