Code Monkey home page Code Monkey logo

aws-extensions-for-dotnet-cli's Introduction

AWS Extensions for .NET CLI

This repository contains AWS tool extensions to the .NET CLI. These tool extensions are focused on building .NET Core and ASP.NET Core applications and deploying them to AWS services. Many of these deployment commands are the same commands the AWS Toolkit for Visual Studio uses to perform its deployment features. This allows you to do initial deployment in Visual Studio and then easily transition from Visual Studio to the command line and automate the deployment.

For example with the AWS Lambda .NET CLI tool extension configured you can deploy a Lambda function from the command line in the Lambda function's project root directory.

dotnet lambda deploy-function MyFunction

The extension will prompt you for missing required parameters. To disable the extension from prompting, set the command line switch --disable-interactive to true.

For a history of releases view the release change log

Installing Extensions

As of September 10th, 2018 these extensions have migrated to be .NET Core Global Tools. As part of the migration each of these tools version number was set to 3.0.0.0

To install these tools use the dotnet tool install command.

dotnet tool install -g Amazon.Lambda.Tools

To update to the latest version of one of these tools use the dotnet tool update command.

dotnet tool update -g Amazon.Lambda.Tools

Migrating from DotNetCliToolReference

To migrate an existing project away from the older project tool, you need to edit your project file and remove the DotNetCliToolReference for the tool package. For example, let's look at an existing Lambda project file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

    <-- The new property indicating to AWS Toolkit for Visual Studio this is a Lambda project -->
    <AWSProjectType>Lambda</AWSProjectType>
  </PropertyGroup>
  
  <ItemGroup>
    <-- This line needs to be removed -->
    <DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" />
  </ItemGroup>
</Project>

To migrate this project, you need to delete the DotNetCliToolReference element, including Amazon.Lambda.Tools. If you don't remove this line, the older project tool version of Amazon.Lambda.Tools will be used instead of an installed Global Tool.

The AWS Toolkit for Visual Studio before .NET Core 2.1 would look for the presence of Amazon.Lambda.Tools in the project file to determine whether to show the Lambda deployment menu item. Because we knew we were going to switch to Global Tools, and the reference to Amazon.Lambda.Tools in the project was going away, we added the AWSProjectType property to the project file. The current version of the AWS Toolkit for Visual Studio now looks for either the presence of Amazon.Lambda.Tools or the AWSProjectType set to Lambda. Make sure when removing the DotNetCliToolReference that your project file has the AWSProjectType property to continue deploying with the AWS Toolkit for Visual Studio.

Supported AWS Services

The following AWS services each have their own .NET CLI tool extension to make it easy to deploy a .NET Core Application to them.

Defaults File

Each tool extension supports a defaults JSON file that is used to preset values for all of the command line switches. When a command is executed it will look for values for the command line switches in this file if they are not specified on the command line. The file is a JSON document where each property name matches the full command line switch excluding the -- prefix.

To avoid confusing missing properties from different tool extensions, each tool extension looks for a different named file in the root of the project.

Tool Extension Defaults File Name
Amazon.ECS.Tools aws-ecs-tools-defaults.json
Amazon.ElasticBeanstalk.Tools aws-beanstalk-tools-defaults.json
Amazon.Lambda.Tools aws-lambda-tools-defaults.json

When deploying with the AWS Toolkit for Visual Studio, you can choose to have the deployment wizard save chosen values into the defaults file. This makes it easy to switch to the command line.

For example, the following aws-ecs-tools-defaults.json has values for the AWS region, AWS credential profile and build configuration. If you use it with an ECS command, you will not need to enter those values.

{
    "region": "us-west-2",
    "profile": "default",
    "configuration": "Release"
}

Use the --config-file switch to use an alternative file. Set the --persist-config-file switch is set to true to persist all of its settings in the defaults file.

Amazon Elastic Container Service (Amazon.ECS.Tools)


This tool extension takes care of building a Docker image from a .NET application and then deploying the Docker image to Amazon Elastic Container Service (ECS). The application must contain a dockerfile instructing this tool and the Docker CLI which this tool uses to build the Docker image.

You must install Docker before using this extension to deploy your application.

Install

To install the extension run the following command.

dotnet tool install -g Amazon.ECS.Tools

Available Commands

Deploy Service
dotnet ecs deploy-service ...

Deploys the .NET Core application as service on an ECS cluster. Services are for long lived process like web applications. Services have a desired number of tasks that will run the application. If a task instance dies for whatever reason the service will spawn a new task instance. Services can also be associated with an Elastic Load Balancer so that each of the tasks in the services will be registered as targets for the load balancer.

Deploy Task
dotnet ecs deploy-task

Deploys the .NET Core application as task on an ECS Cluster. This is good for batch processing and similar jobs where once the process identified in the dockerfile exits the ECS task should end.

Deploy Scheduled Task
dotnet ecs deploy-scheduled-task

Creates a new ECS task definition and then configures a Amazon CloudWatch Event rule to run a task using the new task definition and a scheduled interval.

Push Image
dotnet ecs push-image

Builds the Docker image from the .NET Core application and pushes it to Amazon Elastic Container Registery (ECR). The other ECS deployment tasks first run this command before continuing on with deployment.

AWS Elastic Beanstalk (Amazon.ElasticBeanstalk.Tools)


This tool extension deploys ASP.NET Core applications to AWS Elastic Beanstalk environment.

Install

To install the extension run the following command.

dotnet tool install -g Amazon.ElasticBeanstalk.Tools

Available Commands

Deploy Environment
dotnet eb deploy-environment

Deploys the ASP.NET Core application to a Elastic Beanstalk environment after building and packaging up the application. If the Elastic Beanstalk environment does not exist then the command will create the environment.

Delete Environment
dotnet eb delete-environment

Deletes an environment.

List Environments
dotnet eb list-environments

Lists all of the current running environments along with the URL to access the environment.

AWS Lambda (Amazon.Lambda.Tools)


This tool extension deploys AWS Lambda .NET Core functions.

Install

To install the extension run the following command.

dotnet tool install -g Amazon.Lambda.Tools

Available Commands

Deploy Function
dotnet lambda deploy-function

Deploys the .NET Core Lambda project directly to the AWS Lambda service. The function is created if this is the first deployment. If the Lambda function already exists then the function code is updated. If any of the function configuration properties specified on the command line are different, the existing function configuration is updated. To avoid accidental function configuration changes during a redeployment, only default values explicitly set on the command line are used. The defaults file is not used.

Invoke Function
dotnet lambda invoke-function MyFunction --payload "The Function Payload"

Invokes the Lambda function in AWS Lambda passing in the value of --payload as the input parameter to the Lambda function.

List Functions
dotnet lambda list-functions

List all of the currently deployed Lambda functions.

Delete Function
dotnet lambda delete-function

Delete a Lambda function

Get Function Configuration
dotnet lambda get-function-config

Get the Lambda function's configuration like memory limit and timeout.

Update Function Configuration
dotnet lambda update-function-config

Update the Lambda function's configuration without uploading new code.

Deploy Serverless
dotnet lambda deploy-serverless

Deploys one or more Lambda functions from the Lambda project through CloudFormation. The project uses the serverless.template CloudFormation template to deploy the serverless app along with any additional AWS resources defined in the serverless.template.

CloudFormation stacks created with this command are tagged with the AWSServerlessAppNETCore tag.

List Serverless
dotnet lambda list-serverless

Lists the .NET Core Serverless applications which are identified by looking for the AWSServerlessAppNETCore tag on existing CloudFormation Stacks.

Delete Serverless
dotnet lambda delete-serverless

Deletes the serverless application by deleting the CloudFormation stack.

Package CI
dotnet lambda package-ci

Used for serverless applications. It creates the Lambda application bundle and uploads it to Amazon S3. It then writes a new version of the serverless.template with the location of the Lambda function code updated to where the application bundle was uploaded. In an AWS CodePipeline this command can be executed as part of a CodeBuild stage returning the transformed template as the build artifact. Later in the pipeline that transformed serverless.template can be used with a CloudFormation stage to deploy the application.

Notes

dotnet lambda package-ci inspects and uses the Architectures property of AWS::Serverless::Function to determine the runtime of the package.

For example:

      "Architectures": [
        "arm64"
      ],

will execute dotnet publish with a --runtime argument of value linux-arm64:

The default is linux-x64 (which will execute dotnet publish with a --runtime argument of value linux-x64: )

The Architectures array can be specified either by:

  1. Directly with the path AWS::Serverless::Function
  2. Within the AWS SAM Template syntax Globals

Example of directly with the path AWS::Serverless::Function in a serverless.template:

  ...
  "Resources": {
    "ApiFnMFS3hGenerated": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Architectures": [
          "arm64"
        ],
        "CodeUri": ".",
        "MemorySize": 10240,
        "Timeout": 900,
        "Role": {
          "Ref": "LambdaExecutionRole"
        },
        "PackageType": "Zip",
        "Handler": "MyAssembly.MyNamespace::MyAssembly.MyNamespace.MyClass::MyFunction"
      }
    }
  },
  "Parameters" ...

Example of within the AWS SAM Template syntax Globals in a serverless.template:

...
  "Globals": {
    "Function": {
      "Runtime": "dotnet6",
      "Architectures": [
        "arm64"
      ]
    }
  },
  "Resources": {
    "ApiFnMFS3hGenerated": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Architectures": [
          "arm64"
        ],
        "CodeUri": ".",
        "MemorySize": 10240,
        "Timeout": 900,
        "Role": {
          "Ref": "LambdaExecutionRole"
        },
        "PackageType": "Zip",
        "Handler": "MyAssembly.MyNamespace::MyAssembly.MyNamespace.MyClass::MyFunction"
      }
    }
  },
  "Parameters" ...
Package
dotnet lambda package

Creates the Lambda application bundle that can later be deployed to Lambda.

aws-extensions-for-dotnet-cli's People

Contributors

96malhar avatar abbotware avatar abubakerb avatar ashishdhingra avatar ashovlin avatar awschristou avatar beau-gosse-dev avatar boblodgett avatar dscpinheiro avatar hounddog22030 avatar johnfnz avatar jpeddicord avatar kellertk avatar kuzmenko-oleksandr-km avatar ngl321 avatar normj avatar peterrsongg avatar philasmar avatar ppejovic avatar ppittle avatar rbbarad avatar shaggygi avatar shruti0085 avatar somayab avatar stebaker92 avatar stevejroberts avatar tmakin avatar vellozzi avatar vickramravichandran avatar wmmagee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-extensions-for-dotnet-cli's Issues

Allow EC2 role credentials during function deployment

My build server is an EC2 instance with a role that allows it to do everything it needs to perfrom deployments.

The dotnet lambda deploy-function command doesn't understand this scenario. It assumes you either specify a credential profile or, if you don't, it uses credentials from environment variables. It would be super nifty if it supported using role credentials as well.

It's possible it already supports this and I'm doing something wrong. I tried removing the "profile" value from my aws-lambda-tools-defaults.json file and didn't specify a profile on the command line. I wound up with this error message:

Error determining region for bucket dgi.deploy-lambda: Error determining region for bucket dgi.deploy-lambda: Access Denied

Publish fails to chmod when dll has space in filename

I'm using version 2.1.4 of Amazon.Lambda.Tools. When an assembly has a space in the file name, the publish command will fail to chmod the assembly properly.

csproj

    <Reference Include="HAT Common">
      <HintPath>..\lib\HAT Common.DLL</HintPath>
    </Reference>

Output from publish

//
Changed permissions on published dll (chmod +r CommonDatastream.dll).
... publish: /bin/chmod: cannot access 'HAT': No such file or directory
Changed permissions on published dll (chmod +r Newtonsoft.Json.dll).
//

The chmod file name needs to be quoted when run in shell.

https://github.com/aws/aws-extensions-for-dotnet-cli/blob/dev/src/Amazon.Lambda.Tools/LambdaDotNetCLIWrapper.cs#L174

dotnet lambda function-deploy fails after updating to 2.1.302

I just updated .Net Core (2.1.302) and now I cannot deploy functions to Lambda. I am trying to deploy a 2.0 function and receive this error:
Version for package Amazon.Lambda.Tools could not be resolved.

I have verified that the tools are installed under ~/.nuget. Thanks for any help.

I am on Mac OS 10.13.5.

_Alex

deploy-serverless fails if all resources do not have Properties keys

When running dotnet lambda deploy-serverless, it fails if I have a minimal resource definition with no Properties key like this:

...
  UploadsBucket:
    Type: AWS::S3::Bucket

I get:

...
Uploading to S3. (Bucket: xxx Key: xxx.zip)
... Progress: 10%
... Progress: 21%
... Progress: 24%
... Progress: 29%
... Progress: 40%
... Progress: 51%
... Progress: 54%
... Progress: 59%
... Progress: 70%
... Progress: 81%
... Progress: 84%
... Progress: 89%
... Progress: 100%
Unknown error executing command: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Amazon.Lambda.Tools.LambdaUtilities.UpdateCodeLocationInYamlTemplate(String templateBody, String s3Bucket, String
s3Key)
   at Amazon.Lambda.Tools.Commands.DeployServerlessCommand.<PerformActionAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.<ExecuteAsync>d__10.MoveNext()

If I just change that definition to this it works fine:

...
  UploadsBucket:
    Type: AWS::S3::Bucket
    Properties: {}

ElasticBeanstalk tools different response to "Unable to find credentials" between 3.0.0 and 3.0.1

I'm playing with Elastic Beanstalk for the first time and tried to mistakenly run the deploy command before setting up the AWS credentials.

On Amazon.ElasticBeanstalk.Tools --version 3.0.0 if you try to run the deploy command immediately after installing:
dotnet eb deploy-environment --publish-options "--runtime win-x64"
Then answer the prompts for Application Name, Environment, and Region. You get a message and 3 exceptions:

Unknown error executing command: Unable to find credentials

Exception 1 of 3:
Amazon.Runtime.AmazonClientException: Unable to find the 'default' profile in CredentialProfileStoreChain.
   at Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource source)
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 3:
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.

Exception 3 of 3:
System.Net.Http.HttpRequestException: No route to host ---> System.Net.Sockets.SocketException: No route to host

This is great and informative! But not the same for v 3.0.1.

Doing the same thing command without setting up AWS creds with Amazon.ElasticBeanstalk.Tools --version 3.0.1 results in this:

Unknown error executing command: Host is down
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask)
   at Amazon.Runtime.Internal.Util.AsyncHelpers.<>c__DisplayClass1_1`1.<<RunSync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop()
   at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func`1 task)
   at Amazon.Util.AWSSDKUtils.DownloadStringContent(Uri uri, TimeSpan timeout, IWebProxy proxy)
   at Amazon.Util.EC2InstanceMetadata.GetItems(String relativeOrAbsolutePath, Int32 tries, Boolean slurp)
   at Amazon.Util.EC2InstanceMetadata.get_IAMSecurityCredentials()
   at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
   at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
   at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.ElasticBeanstalk.Tools.Commands.DeployEnvironmentCommand.DoesApplicationExist(String applicationName) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.ElasticBeanstalk.Tools\Commands\DeployEnvironmentCommand.cs:line 414
   at Amazon.ElasticBeanstalk.Tools.Commands.DeployEnvironmentCommand.PerformActionAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.ElasticBeanstalk.Tools\Commands\DeployEnvironmentCommand.cs:line 104
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 44

Which is misleading. You can see in the exception itself that get_IAMSecurityCredentials is a source for the exception, but what happened to the helpful message in 3.0.0? Unable to find credentials?
I also think an instruction to set up the AWS keys/creds would be welcome in the readme.md

dotnet lambda deploy-serverless with template greater than 51,200 bytes

I am receiving the following error when using a serverless.template file that is greater than 50 KB:

Error creating CloudFormation change set: 1 validation error detected: Value 'redacted' at 'templateBody' failed to satisfy constraint: Member must have length less than or equal to 51200

Is there a workaround available? I don't see an option to automatically upload the template to S3, but perhaps I'm missing it.

task-cpu and task-memory are parsed from strings. Unclear in documentation

Because the documentation says:

     --task-cpu                              The amount of cpu to allocate for the task definition. Fargate only.
     --task-memory                           The amount of memory to allocated for the task definition. Fargate only.

it implies that number values should be set. For example:

{
    "task-cpu"                    : 1024,
    "task-memory"                 : 2048
}

However, if you put in integer values, the values aren't parsed and the user is prompted to enter the value. Instead, you must provide string values:

{
    "task-cpu"                    : "1024",
    "task-memory"                 : "2048"
}

Can the help be updated to reflect this? (If you keep it string values).

dotnet lambda deploy/list-function --profile

Hi,
Version:
Amazon Lambda Tools for .NET Core applications (2.2.0)

When running the lambda commands including the --profile , iam getting the following error:
Error listing Lambda functions: Error calling AssumeRole for role arn:aws:iam::1213123213:role/administrator

Why doest this not work? I can run aws cli commands with this profile.
aws s3 ls --profile administrator

My config is as following:
[profile single]
region = eu-west-1
output = text

[profile administrator]
region = eu-west-1
role_arn = arn:aws:iam::121312313:role/administrator
source_profile=single
mfa_serial = arn:aws:iam::121312313:mfa/user@companny

Do i miss something?

Bug: Publish optimization uses a hardcoded runtime linux-x64

LambdaDotNetCLIWrapper.cs has the following optimization, which is supposed to make the resulting zip smaller:

                // If you set the runtime linux-x64 it will trim out the Windows and Mac OS specific dependencies but Razor view precompilation
                // will not run. So only do this packaging optimization if there are no Razor views.
                if (Directory.GetFiles(fullProjectLocation, "*.cshtml", SearchOption.AllDirectories).Length == 0)
                {
                    arguments.Append(" -r linux-x64 --self-contained false /p:PreserveCompilationContext=false");
                }

However, if one has a dependency on some native libraries using nuget packages and such a dependency package has a bunch of monikers and not only linux or linux-x64, but e.g. rhel-x64, the resulting output is unusable, since the publish result will contain a wrong library.
An example of such a package would be LibGit2Sharp.NativeBinaries:

image

Temporary workaround:

Add an empty .cshtml file and a dependency to Microsoft.AspNetCore.Razor so the if in the optimization above is ignored.

no error for wrong parameter name

cli tool version: Tool 'amazon.lambda.tools' was reinstalled with the latest stable version (version '3.1.2').

When a wrong parameter is given, it should print error for wrong parameter name instead of accepting the command.

For example, --tag is not a valid option (certainly, tagname whatever is wrong) , yet it takes it and on its own, ignore and print the list function.
dotnet lambda list-functions --profile yourprofilename --region us-east-1 --tag whatever

Implement Layer support for .NET Core Lambda Functions

Hi,

One of the announcements at re:Invent was the introduction of layers in Lambda.

Whilst it's pretty easy to see the fit in dynamic runtimes like node.js and python, I wonder how applicable is this new feature to a build-ahead runtime like .NET Core.

I can imagine something like dynamic binding of any assembly present in /opt but the list of useful usages of dynamic binding is pretty short in .NET Core (as opposed to .NET Framework where assemblies might be referenced in the app.config file)

Globals no longer supported

I've upgraded from 2.2.0 to 3.1.0 (a big update, I know) and it's broken globals. For example, I have this in my template:

Globals:
  Function:
    Runtime: "dotnetcore2.1"

# later 
  PingFunction:
    Type: "AWS::Serverless::Function"
    Properties:
      FunctionName: !Sub ${Environment}_Ping
      Handler: "LambdaFunctions::LambdaFunctions::Ping"
      Role: !GetAtt LambdaRole.Arn

But attempting deployment fails with:

Unknown error executing command: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Amazon.Lambda.Tools.LambdaUtilities.DetermineTargetFrameworkFromLambdaRuntime(String lambdaRuntime) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\LambdaUtilities.cs:line 31
   at Amazon.Lambda.Tools.TemplateProcessor.TemplateProcessorManager.PackageDotnetProjectAsync(IUpdateResourceField field, String location) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\TemplateProcessor\TemplateProcessorManager.cs:line 203
   at Amazon.Lambda.Tools.TemplateProcessor.TemplateProcessorManager.ProcessUpdatableResourceAsync(String templateDirectory, IUpdateResourceField field) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\TemplateProcessor\TemplateProcessorManager.cs:line 155
   at Amazon.Lambda.Tools.TemplateProcessor.TemplateProcessorManager.TransformTemplateAsync(String templateDirectory, String templateBody) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\TemplateProcessor\TemplateProcessorManager.cs:line 87
   at Amazon.Lambda.Tools.Commands.DeployServerlessCommand.PerformActionAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\Commands\DeployServerlessCommand.cs:line 167
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 44

Debugging through the code, I can see it is because it expects, for example, a Runtime value on the IUpdatableResourceDataSource, but that is null when using a global. I tried adding it manually to my function and it was then present, but obviously I don't want to be doing that.

BUG: dotnet lambda package-ci creates faulty CloudFormation output template with CodeBuild

I created a CloudFormation script with two dotnet core C# lambdas named:

ProcessCreateAccountFromDynamoDBEvent
CreateAccount

When my buildspec.yml file is being executed in CodeBuild, it creates a wrong CloudFormation template output file where it ignores and overwrites the S3Key of Lambda ProcessCreateAccountFromDynamoDBEvent.

Attached is a comparison of the original CloudFormation stack and the output templated generated. The S3Key produced was CreateAccount-636702840090957270.zip. This file was supposed to go ONLY to the CreateAccount Lambda but instead it uses the same key for two seperate Lambdas including the ProcessCreateAccountFromDynamoDBEvent Lambda.

Please fix this ASAP. Thank you!

image

Install on Ubuntu 18.04 with DotnetToolSettings.xml not found in packate

I was trying to install this on an 18.04 instace on aws.

To recreate

Spin up an instance of Ubuntu 18.04LTS on amazon - (ami: ami-00035f41c82244dab)
Free tier is fine
Install dotnet as per instructions here: https://www.microsoft.com/net/download/linux-package-manager/ubuntu18-04/sdk-current

Install the elastic beanstalk tools (the others fail in the same way)

dotnet tool install -g Amazon.ElasticBeanstalk.Tools

Fails with:

"The settings file in the tool's NuGet package is invalid: Settings file 'DotnetToolSettings.xml' was not found in the package.
Tool 'amazon.elasticbeanstalk.tools' failed to install. Please contact the tool author for assistance."

Obsevations:

I'm running ubuntu 18.04 locally with the Mate desktop and got the tools to install and run fine, this may be a bug downstream? I'm using zsh locally if that has any impact.

"Missing required parameter: --launch-type" error with deploy-scheduled-task.

deploy-scheduled-task appears to be missing command options that are present in the comparable deploy-service.

Here's a close copy of what I am using in my build script:

dotnet ecs deploy-scheduled-task
--disable-interactive true
--project-location ExampleService
--region region
--profile default
--configuration Release
--tag exampleservice:latest
--cluster cluster
--launch-type EC2
--task-definition-name ExampleService
--task-definition-network-mode bridge
--task-definition-task-role arn:aws:iam::account-number:role/ecs-role
--container-name ExampleService
--container-memory-hard-limit 128
--container-memory-soft-limit 128
--container-port-mapping ''
--container-environment-variables '"ENVIRONMENT"="Production"'
--skip-image-push false
--rule ExampleService
--rule-target ExampleService
--schedule-expression 'cron(15 0 * * ? *)'
--cloudwatch-event-role arn:aws:iam::account-number:role/role-name
--desired-count 1

This will build the docker image and push it, then fail with the error Missing required parameter: --launch-type when it goes to update the scheduled task definition.

This is with version 3.0.0 of Amazon.ECS.Tools installed globally.

Question - How to run AWS Lambda Deploy task without accessing source code(or csproj)?

Hi there,

Looking ways to run AWS Lambda Deploy task without accessing source code(or csproj)?

Current Build definitions(using VSTS) requires to copy the source code(or csproj) file to artifacts and Release pipeline(using VSTS) to call AWS Lambda Deploy task, which calls dotnet lambda deploy-serverless that runs dotnet build.

  • Any way to remove the necessity to remove the requirement to source code(or csproj file) to AWS Lambda Deploy task?

  • Any timeline for the .Net Core 2.1 Global Tools Support? Guessing that will be the one of the main purpose of that command line tool.

dotnet eb deploy-environment command timeout

Getting a timeout issue when deploying my netcore app to EB. Here are the details :

Uploading to S3. (Bucket: elasticbeanstalk-ap-southeast-2-043897850050 Key: Pavoni/AWSDeploymentArchive_636847158216790790.zip)
... Progress: 10%
... Progress: 20%
... Progress: 30%
... Progress: 40%
... Progress: 50%
... Progress: 60%
... Progress: 70%
Error uploading application bundle to S3: Error uploading to App/AWSDeploymentArchive_App_636847158216790790.zip in bucket elasticbeanstalk-ap-southeast-2-043897850050: A task was canceled.

.NET 2.1 - MVC's compile time auto-discovery not working

Hi Folks,

I had this issue where controllers declared in class libraries where working as expected behind IIS, but not when deployed to AWS Lambda (C# .NET 2.1). This issue however can be resolved temporarily by adding the class library as application part in Web API.

Folks at ASP.NET MVC team, helped identify the issue as described in the below link.
aspnet/Mvc#8095 (comment)

Can lambda-dotnet-cli also change to compile time graph for auto discovery of controllers?

dotnet lambda deploy-serverless fails in .UpdateCodeLocationInJsonTemplate

Hello all, I am a newbie to AWS and was playing with some Lambda. The source is here: https://github.com/diacoda/Car.
I have run botnet lambda package and got a CarFunction-deploy.zip.

Now, I am trying to run:
dotnet lambda deploy-serverless --package CarFunction-deploy.zip and I am failing with
AWS Lambda Tools for .NET Core functions (2.1.1)
Project Home: https://github.com/aws/aws-lambda-dotnet

Skipping compilation and using precompiled package CarFunction-deploy.zip
Uploading to S3. (Bucket: 204891-lambda-deploy Key: prefix204891-CarLambda-sn-636590941237757320.zip)
... Progress: 50%
... Progress: 100%
Unknown error executing AWS Serverless deployment: Object reference not set to an instance of an object.
at Amazon.Lambda.Tools.Utilities.UpdateCodeLocationInJsonTemplate(String templateBody, String s3Bucket, String s3Key)
at Amazon.Lambda.Tools.Commands.DeployServerlessCommand.d__67.MoveNext()

The content of aws-lambda-tools-defaults.json can be found on GitHub or below for your convenience:
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",

"dotnet lambda help",

"All the command line options for the Lambda command can be specified in this file."
],

"profile":"tr-fr-sandbox",
"region" : "us-east-2",
"configuration" : "Release",
"framework" : "netcoreapp2.0",
"function-runtime":"dotnetcore2.0",
"s3-bucket" : "204891-lambda-deploy",
"s3-prefix" : "prefix",
"template" : "serverless.json",
"stack-name" : "204891-CarLambda-sn",
"stack-wait" : true,
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "CarFunction::CarFunction.Functions::Get"
}

serverless.json:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Transform" : "AWS::Serverless-2016-10-31",

"204891-CarLambda" : {
"Type" : "AWS::Serverless::Function",
"Properties": {
"Handler": "CarFunction::CarFunction.Functions::FunctionHandler",
"Runtime": "dotnetcore2.0",
"CodeUri": ".",
"Description": "Function to get a list of carss",
"MemorySize": 256,
"Timeout": 30,
"Role": "arn:aws::role/204891-lambdabasic" },
"Events": {
"Api1": {
"Type": "Api",
"Properties": {
"Path": "/{o+}",
"Method": "ANY"
}
},
"Api2": {
"Type": "Api",
"Properties": {
"Path": "/Cars",
"Method": "GET"
}
}
}
}
}

Any help is much appreciated. I have no idea why is failing...
At some point in time I tried the package-ci but could not get it to work so I thought this deploy-serverless should be easier ... well... Need your help.

Thanks! Dan

PS: For reference I am on a Mac with VS Code.

When using -pcfg true tag, tag value written to file includes full ARN

Sorry if I'm being a pain. Think of this as a free QA person.

If you run a command that saves the config values back to the json file such as:

dotnet ecs deploy-task -cfg foo.json -pcfg true

When the tag is written back, it will pre-pend the ARN name. For example if my tag was:

"tag"     : "console-tester:latest"

When the file is written back, that is changed to

"tag": "SECRETSTUFF.dkr.ecr.us-east-1.amazonaws.com/console-tester:latest",

If you run the task again, you actually create a new repository with that long name.

(Sorry. I know you just released a version. Low priority bug. Just letting you know it's there.)

Deploy-Function with config-file and project-location issue

Hi,

When calling dotnet deploy-function with a project-location set to a sub-directory and config-file specified, it falls back to using interactive prompts instead of using parameters from the file.

Example that works (current dir in app):

dotnet lambda deploy-function -cfg my-config-file.json

Example that doesn't work (2 directories up):

dotnet lambda deploy-function -pl ./src/App -cfg ./src/App/my-config-file.json

This then prompts for the framework version:

Enter Framework: (Target framework to compile, for example netcoreapp2.1.)

The cfg file path seems correct, because if I deliberately make it wrong then I get an expected "Config file [...] cannot be found".

I can cd to the correct directory, but when running from a CI tool it's much more useful to specify the path and stay in the root directory.

Migrating from DotNetCliToolReference breaks CI CD pipeline

Hi,
I am trying to migrate an existing project from old tool to .NET Core global tools.
My buildspec.yml file:
version: 0.2 phases: pre_build: commands: - dotnet restore --configfile NuGet.Config build: commands: - cd BestHealth.AWS.Lambda - dotnet tool install -g Amazon.Lambda.Tools - dotnet lambda package-ci --template serverless.template --s3-bucket bha-codebuild-deployment-artifacts --output-template updated-serverless.template.json artifacts: files: - ./BestHealth.AWS.Lambda/updated-serverless.template.json - ./BestHealth.AWS.Lambda/stage_template_configuration.json - ./BestHealth.AWS.Lambda/prod_template_configuration.json discard-paths: yes

And my .csproj file is as below:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> <AWSProjectType>Lambda</AWSProjectType> </PropertyGroup> <ItemGroup> <Compile Remove="OldLambdaFunctions.cs" /> </ItemGroup> <ItemGroup> <PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="1.1.3" /> <PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" /> <PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" /> <PackageReference Include="AWSHelper" Version="1.0.0.36" /> <PackageReference Include="AWSSDK.CognitoIdentity" Version="3.3.2.34" /> <PackageReference Include="AWSSDK.CognitoIdentityProvider" Version="3.3.11.3" /> <PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.14.2" /> <PackageReference Include="AWSSDK.S3" Version="3.3.24" /> <PackageReference Include="AWSSDK.SimpleEmail" Version="3.3.6.20" /> <PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.3.1.11" /> </ItemGroup> <ItemGroup> </ItemGroup> <ItemGroup> <Reference Include="AWSSDK.CognitoIdentity"> <HintPath>..\..\..\..\.nuget\packages\awssdk.cognitoidentity\3.3.2.22\lib\netstandard1.3\AWSSDK.CognitoIdentity.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> <Folder Include="Table\" /> </ItemGroup> </Project>

dotnet lambda package-ci command throws an error:

[Container] 2018/10/08 07:28:24 Running command dotnet lambda package-ci --template serverless.template --s3-bucket bha-codebuild-deployment-artifacts --output-template updated-serverless.template.json
No executable found matching command "dotnet-lambda"

[Container] 2018/10/08 07:28:24 Command did not exit successfully dotnet lambda package-ci --template serverless.template --s3-bucket bha-codebuild-deployment-artifacts --output-template updated-serverless.template.json exit status 1
[Container] 2018/10/08 07:28:24 Phase complete: BUILD Success: false
[Container] 2018/10/08 07:28:24 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: dotnet lambda package-ci --template serverless.template --s3-bucket bha-codebuild-deployment-artifacts --output-template updated-serverless.template.json. Reason: exit status 1

Renaming parameters with Lambda tool

Hello,

I tried to deploy a new version of a stack with renamed parameters, however, Amazon Lambda Tools v.2.1.4 is expecting the old named parameters as well.

Command:
dotnet lambda deploy-serverless --package /home/jenkins/workspace/jenkins.template --config-file /home/jenkins/workspace/aws-lambda-tools-stage.json --template-parameters Environment=stage

Exception:
Error creating CloudFormation change set: Parameters: [FunctionNameMetadata, FunctionNameValidate, HandlerNameMetadata, HandlerNameValidate] do not exist in the template

CloudFormation script:

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
  Environment:
    Type: String
  FunctionName:
    Type: String
    Default: albx-analyzer-api-lambda
  HandlerName:
    Type: String
    Default: Albelli.AlbxAnalyzer.Api::Albelli.AlbxAnalyzer.Api.LambdaEntryPoint::FunctionHandlerAsync

How can I rename or delete cloud formation parameters without deleting the stack?

aws-lambda-tools-defaults.json documentation

Is there documentation for aws-lambda-tools-defaults.json somewhere? I've been Googling it and can't find anything. Only by sheer luck did I stumble across the template-substitutions property in an example and it would have come in handy a looong time ago. It would be great to see what other value I'm missing out on.

Also, is it possible to define multiple template-substitutions? I tried using an array of strings but it doesn't seem to work.

Thanks!

Yaml templates with intrinsic functions that use the short form don't work

dotnet lambda deploy-serverless roundtrips the template using YamlDotNet so that it can update some values (Code Uri and such). This unfortunately completely destroys the intrinsic functions in the template.

For example, add the following Condition to a template and then deploy it

  StandardStack: !Equals [!Ref 'AWS::StackName', bla]

If you look at what's get uploaded by dotnet lambda deploy-serverless in the CloudFormation console then you will see that the !Equals is dropped. This is a bug in YamlDotNet. I just created a PR to fix this here.

dotnet eb package / deploy from package command?

Seems that you can't create a package (and then deploy later) using the eb tools like you can create a lambda package.

Is there are reason why not?

It seems like it should be fairly simple to break up 'deploy-environment' into these two steps so it can be better suited for CI / Build systems.

Cannot set parameter

I'm using version 2.1.4 of Amazon.Lambda.Tools. I have a parameter in my YAML template like this:

Parameters:
  Environment:
    Type: "String"

But when I try and set it like this:

dotnet lambda deploy-serverless -t serverless.yaml --template-parameters Environment=whatever

I get this output:

Skipping passed in template parameter Environment because the template does not define that parameter

The same deployment works if I use sam directly at the CLI, and the parameter is passed through as expected.

Parameterizing swagger file

Hi,

My aim is to have multiple batch files which would deploy my serverless application to different environments (e.g dev/test/live). It is worth mentioning that these environments all live on separate aws accounts. The reason I need to use the swagger files is to set up CORS and Cognito Authentication. I realise CORS can be set up directly in the sam template, however Cognito Authentication cant. I would also like the functionality of using multiple user pools which using swagger allows me to do.

So far, I have created batch files that can deploy to different environments by using
dotnet lambda deploy-serverless --profile {profile} --s3-bucket {bucket} --stack-name {stack} --region {region}

By not including the swagger file, this works fine to just deploy to different environments when I need to.
However I need to set up Cors and Cognito Authentication manually via aws console. Also the console doesn't allow multiple user pool cognito authentication so that bit I can't do.

How can I parameterize the swagger file to pass in different values for different environments when running my batch files?
What parts of the swagger file is actually REQUIRED for the swagger to still work? (What bits can I strip out basically)

Thanks
Ridhwan

Amazon Lambda Tools 3.0.0 | With --package {path.zip} provided, No .NET project found in directory * to build.

Hi
trying to use the new Amazon Lambda Tools 3.0.0 , after installing the tools globally in CI/CD pipeline ,
I create the pacakge.zip using dotnet lambda package in the build server ( TeamCity).
From the deployment server (Octo) I'm deploying using : dotnet lambda deploy-serverless mystackname --package pacakge.zip --template serverless.template --s3-bucket mybucket--s3-prefix folder1/code/

I'm getting "No .NET project found in directory D:\Projects\enforcement-adapters to build.", my understanding is providing --package no further build is required, right ?

Providing --project-location will solve the issue, but again I have to pack my source code / *.csproj file, is there away to avoid this ?

Need a dotnet s3 upload command

My company uses terraform and bitbucket pipelines. I'm currently using dotnet lambda package to create a zip file, but I need a simple way to transfer that to an S3 bucket without getting cloud formation involved.

For now I'm having to install pip and aws cli, but it'd be nice to have a simple dotnet tool for this as well.

It can work similar to aws cli cp command. I'll need some way to specify the --sse-kms-key-id

dotnet lambda deploy-serverless s3 upload timeouts

Hi There,

I am receiving timeouts whenever I try to publish from the cli using dotnet lambda deploy-serverless

Error uploading to XXX in bucket YYY: A task was canceled.

I don't receive this error when publishing from Visual Studio.

Anecdotally it seems to timeout after 2 minutes.

Is there a setting somewhere that I can adjust to increase this timeout?

It's a problem because I am deploying files that need the executable bit set on them and the visual studio tool can't deal with that. I really need to deploy it from a linux machine.

I'd really appreciate any guidance or workarounds you can offer because this has blocked me on this project at the moment.

I tried creating the zip on linux and deploying with the --pac option but that didn't work either.

dotnet lambda deploy-function does not display code in AWS lambda editor

Deploying a lambda function creates the function in AWS but does not appear to load the code correctly using amazon.lambda.tools 3.1.0 on OSX 10.14 and dotnet core 2.1.302

steps to reproduce

dotnet lambda deploy-function
Amazon Lambda Tools for .NET Core applications (3.1.0)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Executing publish command
Deleted previous publish folder
... invoking 'dotnet publish', working folder '/Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/publish'
... Disabling compilation context to reduce package size. If compilation context is needed pass in the "/p:PreserveCompilationContext=false" switch.
... publish: Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish: Restore completed in 50.69 ms for /Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/AWSLambda1.csproj.
... publish: AWSLambda1 -> /Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/rhel.7.2-x64/AWSLambda1.dll
... publish: AWSLambda1 -> /Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/publish/
Changed permissions on published dll (chmod +r AWSLambda1.dll).
Changed permissions on published dll (chmod +r Newtonsoft.Json.dll).
Changed permissions on published dll (chmod +r Amazon.Lambda.Core.dll).
Changed permissions on published dll (chmod +r Amazon.Lambda.Serialization.Json.dll).
Zipping publish folder /Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/publish to /Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/AWSLambda1.zip
... zipping: adding: AWSLambda1.runtimeconfig.json (deflated 23%)
... zipping: adding: AWSLambda1.pdb (deflated 27%)
... zipping: adding: AWSLambda1.dll (deflated 56%)
... zipping: adding: AWSLambda1.deps.json (deflated 81%)
... zipping: adding: Newtonsoft.Json.dll (deflated 60%)
... zipping: adding: Amazon.Lambda.Core.dll (deflated 57%)
... zipping: adding: Amazon.Lambda.Serialization.Json.dll (deflated 56%)
Created publish archive (/Users/leeatkinson/Work/sharp/core/AWSLambda1/AWSLambda1/bin/Release/netcoreapp2.1/AWSLambda1.zip).
Enter Function Name: (AWS Lambda function name)
AWSLambda1
Updating code for existing function <---- seems to upload code but does not display in editor

screenshot 2018-10-31 at 08 40 03

aws-ecs-tools-defaults.json does not appear to parse desired-count

If you pass --desired-count 1 or -dc 1 on the command line for dotnet ecs deploy-schedule-task, the task count is correctly set. If you set the value in the default json file, the value is not found and it doesn't default to a value of 1 per the documentation. Instead it throws an error of

Error creating CloudWatch Event target: 1 validation error detected: Value '0' at 'targets.1.member.ecsParameters.taskCount' failed to satisfy constraint: Member must have value greater than or equal to 1

A snippet of my json file:

{
    ...
    "task-execution-role"         : "ecsTaskExecutionRule",
    "desired-count"               : 1,
    "task-cpu"                    : "1024",
    "task-memory"                 : "2048"
}

I can see in code where this is parse, but it's not clear why it's not picking up the json value.

How do I specify the version label of the code I'm deploying with "dotnet eb deploy-environment"?

There it is, in the issue name. Sorry for asking a question instead of reporting an issue, but I don't seem to be able to find the right CLI switch and I would like to be able to specify something that would help to trace the app version to an actual commit, or specify something more semantic.

Edit:

As far as I understand, this is where it is configured. Is it possible to make it into a command?

Unknown error executing command: (...): While parsing a block mapping, did not find expected key.

My CodeBuild is not working and it fails with error:

Unknown error executing command: (Line: 41, Col: 42, Idx: 1423) - (Line: 41, Col: 54, Idx: 1435): While parsing a block mapping, did not find expected key.

Here is the stacktrace from the CodeBuild output:

Unknown error executing command: (Line: 41, Col: 42, Idx: 1423) - (Line: 41, Col: 54, Idx: 1435): While parsing a block mapping, did not find expected key.
   at YamlDotNet.Core.Parser.ParseBlockMappingKey(Boolean isFirst)
   at YamlDotNet.Core.Parser.MoveNext()
   at YamlDotNet.Core.ParserExtensions.Allow[T](IParser parser)
   at YamlDotNet.Core.ParserExtensions.Expect[T](IParser parser)
   at YamlDotNet.RepresentationModel.YamlScalarNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlDocument..ctor(IParser parser)
   at YamlDotNet.RepresentationModel.YamlStream.Load(IParser parser)
   at Amazon.Lambda.Tools.LambdaUtilities.UpdateCodeLocationInYamlTemplate(String templateBody, String s3Bucket, String s3Key) in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\LambdaUtilities.cs:line 440
   at Amazon.Lambda.Tools.Commands.PackageCICommand.PerformActionAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Lambda.Tools\Commands\PackageCICommand.cs:line 132
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in E:\JenkinsWorkspaces\aws-extensions-for-dotnet-cli\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 43

[Container] 2018/10/01 16:41:08 Command did not exit successfully dotnet lambda package-ci --s3-bucket us-east-1-dev-altosignal-deployments --template pipeline.yml --output-template serverless.yaml exit status 255
[Container] 2018/10/01 16:41:08 Phase complete: BUILD Success: false
[Container] 2018/10/01 16:41:08 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: dotnet lambda package-ci --s3-bucket us-east-1-dev-altosignal-deployments --template pipeline.yml --output-template serverless.yaml. Reason: exit status 255

I have attached the CloudFormation input template file named pipeline.yml. When the buildspec command

dotnet lambda package-ci --s3-bucket us-east-1-dev-altosignal-deployments --template pipeline.yml --output-template serverless.yaml

locally it produces the following serverless.yaml file (it's attached).

Please help since this is holding us back with development.

StackoverflowQuestion.zip

Zip files not optimised when using Microsoft.NET.Sdk project type

When I dotnet lambda publish in an Microsoft.NET.Sdk.Web project, much of the asp.net dlls are not included in the zip file leading to a lean zip file (often < 1MB).

My current project requires lambdas driven by SNS and therefore I use the Microsoft.NET.Sdk project type; when I perform dotnet lambda publish, the resulting zip still contains those Microsoft.AspNetCore.* dlls with a resulting ZIP of around 16MB!

Would be good to expose --no-fail-on-empty-changeset to CLI

In aws/aws-cli#2922 a flag for the AWS cli was added to that a cloudformation stack/template that was deployed with no changes would not return non-zero (useful for automated deploys that may not always contain changes). It would be super if this could be leveraged in the dotnet extensions. I am currently working around this by inspecting the output for a specific string, but it feels very fragile.

Serverless application CI/CD pipeline

Hi,
I am successfully using AWS Serverless Application as a mobile backend. We are still in DEV stage and it's so far so good.
I need some help setting up CI/CD pipeline. We are using GitHub for source repository.

I have a dotnet serverless aplication in .NET Core 2.1 environment to deploy multiple lambda functions.
I have cloudformation project that contains 2 templates 1) Cognito user pools and roles 2) DynamoDB
I have attached an image showing my current setup in .NET environment.
awsarchitecture

I want to set up a codepipeline with source as Git so that

  1. Any changes in above solution triggers the build
  2. I want to deploy separate DEV/TESTING/UAT environment. My templates already takes these stages as input parameter to templates and create different resources.
  3. How do I provide static stage variable values for 3 environment? For example, if I make some change, I want to deploy that change to DEV/TESTING etc. However I want to use same templates in all 3 environments but having different environment values. So should I create 3 new Git branches? If yes, how do I provide different input value to templates in these 3 branches?
  4. Can I refer to any sample that mentions what should be the contents of serverless.template and build.yaml file for the CI/CD Pipeline?

Thanks in advance.

3.1.0 of Amazon.Lambda.Tools with package-ci no longer publishes build output to S3 folder

I'm trying to get my lambda function to be pubslihed after a successful build using the latest Amazon.Lambda.Tools v3.1.0.

Running command dotnet lambda package-ci --s3-bucket altosignal-lambda-functions --template pipeline.yml --output-template serverless.yaml locally or in my buildspec.yml file (for CodeBuild) only produces the serverless.yaml file which does not have an updated S3Key and stays the same as the original S3Key.

The S3 folder altosignal-lambda-functions is empty and I would have assumed that package-ci would enter the publish command. Instead, all I get is this:

 Processing CloudFormation resource lamCreateAccountFromApi
 Writing updated template: serverless.yaml

So, it never published anything to the S3 folder altosignal-lambda-functions. My lambda CloudFormation script looks like this:

lamCreateAccountFromApi:
    Type: AWS::Lambda::Function
    Properties:
        FunctionName: !Ref RepoName
        Handler: !Sub ${RepoName}::${RepoName}.Function::FunctionHandler
        Role:
            Fn::ImportValue:
                !Sub ${Env}-${AWS::Region}-global-iamprocesscommandsfromapigateway-arn
        Code:
            S3Bucket: altosignal-lambda-functions
            # S3Key: !Sub ${RepoName}.zip
            S3Key: CreateAccountFromApi.zip
            # ZipFile: CreateAccountFromApi.zip
        Runtime: dotnetcore2.1
        MemorySize: 128
        Timeout: 30

When I comment out S3Bucket and S3Key and then use the ZipFile above, package-ci does enter into the publish mode and uploads the build into the S3 folder. However, this does not work with CloudFormation changeset detection and CloudFormation stops the CodePipeline with error:

 Exactly one of S3Bucket and ZipFile must be specified

Based on the CloudFormation documenation here, you can not specify only a ZipFile for dotnetcore2.1. So, you must specify an S3Bucket and S3Key for dotnetcore2.1 projects. Also, based on CloudFormation documenation here, the Code property is required.

As it stands, I can not publish any more using package-ci. Please help!

EB deploy-environment timeout causing failure on slow networks

The dotnet eb deploy-environment command seems to have a timeout which causes failure on slower networks with larger projects. On faster networks, it is fine, but on slower ones, I'm getting an "Error uploading application bundle to S3" with the reason "A task was cancelled," usually at about 60%.

Is there a way either to pass the timeout via a configuration variable, or to increase the default timeout for S3 uploads?

Can only set one template parameter

Finally got around to trying the fix for #18, and it seems there's another bug: it only works for one parameter. If I try to specify a second using -tp First=foo;Second=bar I get:

Template Parameters Applied:
        First: foo
Error creating CloudFormation change set: Parameters: [Second] must have values

And if I try and specify -tp twice, it only applies the last one.

Segfault with latest lambda tools

Segfault on dotnet lambda command

kernel: [42898.833720] dotnet-lambda[3674]: segfault at 0 ip 0000000000000000 sp 00007ffd8abced58 error 14 in dotnet-lambda[3ff000+1000]

Is there anything else I need to provide to understand what is the issue?

dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.2.104
 Commit:    73f036d4ac

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /snap/dotnet-sdk/29/sdk/2.2.104/

Host (useful for support):
  Version: 2.2.2
  Commit:  a4fd7b2c84

.NET Core SDKs installed:
  2.2.104 [/snap/dotnet-sdk/29/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.2 [/snap/dotnet-sdk/29/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.2 [/snap/dotnet-sdk/29/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.2 [/snap/dotnet-sdk/29/shared/Microsoft.NETCore.App]

dotnet tool list -g

Package Id               Version      Commands     
---------------------------------------------------
amazon.lambda.tools      3.1.2        dotnet-lambda

How to use 'dotnet ecs deploy-service' with CodePipeline, Fargate, and CloudFormation?

How do I use the dotnet ecs deploy-service CLI command during a CodeBuild phase in a CodePipeline that is managed with CloudFormation?

I could probably figure out the command line options but I do not see any options for CloudFormation like the Lambda extension for aws-extensions-for-dotnet-cli where there is a package-ci command available.

Do you have any examples available?

Deploy serverless ignore "profile-location"

According to the help for command deploy-serverless you can set
--profile-location
Optional override to the search location for Profiles, points at a shared credentials file

I tried to set this option both in config file and as a command line option but the command seems to ignore it.

Am I missing something?

Warning message when deploying Lambda function written in language other than C#

I write my Lamda functions in F#.

I just happened to notice today that I get this error message during my dotnet lambda deploy-function build step:

Unable to determine csproj project file when validating version of Microsoft.AspNetCore.All

This comes from code in src/Amazon.Lambda.Tools/LambdaUtilities.cs that assumes that everything is written in C#.

I think the fix is as simple as examining *.vbproj and *.fsproj files in the same way the *.csproj files are examined, since the project files are basically the same.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.