0

To deploy to EBS (Elastic Beanstalk) I used to run dotnet publish -r linux-x64 --self-contained true --output build in my terminal and then go to the build folder, select all files, compress to zip file, and upload to Elastic Beanstalk in the EBS console. The app fully worked on EBS when deployed this way.

Now I am automating it by using AWS CodePipelines.

I followed this tutorial.

I added this "buildspec.yml" to the root of my project:

version: 0.2
phases:
  install:
    commands:
      - curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel STS
    # runtime-versions: 
    #   dotnet: 7.0
  pre_build:
    commands:
      - dotnet restore Vepo.Web/Vepo.Web.csproj
      - dotnet restore Vepo.Services/Vepo.Services.csproj
      - dotnet restore Vepo.Infrastructure/Vepo.Infrastructure.csproj
      - dotnet restore Vepo.Domain/Vepo.Domain.csproj
      - dotnet restore Vepo.DataContext/Vepo.DataContext.csproj
      - dotnet restore Vepo.Data/Vepo.Data.csproj
      - dotnet restore Vepo.Common/Vepo.Common.csproj
      - dotnet restore Vepo.Application/Vepo.Application.csproj
  build:
    commands:
      - dotnet build -r linux-x64 --self-contained true Vepo.Web/Vepo.Web.csproj
  post_build:
    commands:
      - dotnet publish -r linux-x64 --self-contained true -c Release -o ./app/ Vepo.Web/Vepo.Web.csproj
artifacts:
  files:
    - "**/*"

and this Procfile:

web: dotnet ./app/Vepo.Web.dll

It deploys to EBS successfully. However in the EBS logs, it shows:

Jul 31 01:22:14 ip-172-31-1-234 web: Unhandled exception. System.Exception: Could not resolve a service of type 'Vepo.Infrastructure.IGroceryItmsSearchIndexService' for the parameter 'searchIndexService' of method 'Configure' on type 'Vepo.Web.Startup'. Jul 31 01:22:14 ip-172-31-1-234 web: ---> System.ArgumentNullException: Value cannot be null. (Parameter 'uriString') Jul 31 01:22:14 ip-172-31-1-234 web: at System.ArgumentNullException.Throw(String paramName) Jul 31 01:22:14 ip-172-31-1-234 web: at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName) Jul 31 01:22:14 ip-172-31-1-234 web: at System.Uri..ctor(String uriString) Jul 31 01:22:14 ip-172-31-1-234 web: at Vepo.Infrastructure.SearchService..ctor(String uri, String username, String password, String defaultIndex, Boolean forceInMemory, Boolean refreshOnUpdate) in /codebuild/output/src3059167450/src/Vepo.Infrastructure/Search/Search.cs:line 42 Jul 31 01:22:14 ip-172-31-1-234 web: at Vepo.Web.Startup.b__8_7(IServiceProvider serviceProvider) in /codebuild/output/src3059167450/src/Vepo.Web/Startup.cs:line 211 Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.b__0(ServiceProviderEngineScope scope) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) Jul 31 01:22:14 ip-172-31-1-234 web: --- End of inner exception stack trace --- Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) Jul 31 01:22:14 ip-172-31-1-234 web: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) Jul 31 01:22:14 ip-172-31-1-234 web: at Vepo.Web.Program.Main(String[] args) in /codebuild/output/src3059167450/src/Vepo.Web/Program.cs:line 12

The errors seem to indicate that my GroceryItmsSearchIndexService is no longer registered and my "appsettings.json" file is not working anymore because this is the code in Startup.cs where the errors occur:

    services.AddScoped<ISearchService, SearchService>(serviceProvider =>
    {
        return new SearchService(
                Configuration["openSearchEndpoint"],
                Configuration["openSearchUsername"],
                Configuration["openSearchPassword"],
                Configuration["openSearchIndexName"]);
    });

    services.AddScoped<IGroceryItmsSearchIndexService, GroceryItmsSearchIndexService>();

Where this:

web: at Vepo.Infrastructure.SearchService..ctor(String uri, String username, String password, String defaultIndex, Boolean forceInMemory, Boolean refreshOnUpdate)

Is referring to the code above passing in nulls where Configuration["openSearchXXX"] is passed in.

Any idea what is going on?

BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287

1 Answers1

0

This person had a similar issue. The issue is the Procfile. The Procfile associates "appsettings.json" with the app by running the dll from the location that contains the appsettings.json.

Procfile before:

web: dotnet ./app/Vepo.Web.dll

Procfile after:

web: cd app && dotnet Vepo.Web.dll
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287