-
Notifications
You must be signed in to change notification settings - Fork 875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWS dotnet Lambda example #453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, great to see this working! LGTM, left several comments inline.
aws-cs-lambda/README.md
Outdated
1. Build and publish the lambda function, making the output available to our Pulumi program. | ||
|
||
```bash | ||
cd dotnetLambda/src/dotnetLambda/ && dotnet restore && dotnet build && dotnet publish && cd ../../../ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You don't have to cd
back and forth, you can pass the folder as a parameter to dotnet x
aws-cs-lambda/README.md
Outdated
1. Build and publish the lambda function, making the output available to our Pulumi program. | ||
|
||
```bash | ||
cd dotnetLambda/src/dotnetLambda/ && dotnet restore && dotnet build && dotnet publish && cd ../../../ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call restore
and build
: publish
will do both implicitly
aws-cs-lambda/README.md
Outdated
--payload '"foo"' \ | ||
output.json | ||
|
||
cat output.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cat
won't work on Windows, which might be important for a .NET guide. We use curl
in many examples though, so I'm not sure if it's a problem and what an alternative should be.
{ | ||
public class Function | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove the empty line
aws-cs-lambda/pulumi/Program.cs
Outdated
|
||
class LambdaUtil | ||
{ | ||
public static Pulumi.AssetArchive buildArchive(string lambdaArchivePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method names should be in PascalCase
aws-cs-lambda/pulumi/Program.cs
Outdated
{ | ||
var immutableDictBuilder = System.Collections.Immutable.ImmutableDictionary.CreateBuilder<string, AssetOrArchive>(); | ||
immutableDictBuilder.Add(".", new FileArchive(lambdaArchivePath)); | ||
return new Pulumi.AssetArchive(immutableDictBuilder.ToImmutable()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulumi.
is redundant here
aws-cs-lambda/pulumi/Program.cs
Outdated
var lambda = new Function("basicLambda", new FunctionArgs | ||
{ | ||
Runtime = "dotnetcore2.1", | ||
Code = LambdaUtil.buildArchive("../dotnetLambda/src/dotnetLambda//bin/Debug/netcoreapp2.1/publish"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass FileArchive
directly to Code
, so I don't think the buildArchive
function is needed at all
aws-cs-lambda/pulumi/Program.cs
Outdated
} | ||
} | ||
|
||
class Program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the Program
class on top so that people would see it first. Usual C# practice is to have one class per file, but that's not required here. You could also merge two classes into one with two methods.
aws-cs-lambda/pulumi/Program.cs
Outdated
var lambda = new Function("basicLambda", new FunctionArgs | ||
{ | ||
Runtime = "dotnetcore2.1", | ||
Code = LambdaUtil.buildArchive("../dotnetLambda/src/dotnetLambda//bin/Debug/netcoreapp2.1/publish"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code = LambdaUtil.buildArchive("../dotnetLambda/src/dotnetLambda//bin/Debug/netcoreapp2.1/publish"), | |
Code = LambdaUtil.buildArchive("../dotnetLambda/src/dotnetLambda/bin/Debug/netcoreapp2.1/publish"), |
|
||
using Pulumi; | ||
using Pulumi.Aws.Lambda; | ||
using Pulumi.Aws.Iam; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: alphabetize the usings within each group
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. | ||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] | ||
|
||
namespace dotnetLambda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespaces shoudl be PascalCased in C#.
public string FunctionHandler(string input, ILambdaContext context) | ||
{ | ||
return input?.ToUpper(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider:
public string FunctionHandler(string input, ILambdaContext context)
=> input?.ToUpper();
aws-cs-lambda/pulumi/Program.cs
Outdated
Role = LambdaUtil.createLambdaRole().Arn | ||
}); | ||
|
||
return new Dictionary<string, object>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this all one line, or put the {
on the next line. consider also just running an explicit format on all your docs.
aws-cs-lambda/pulumi/Program.cs
Outdated
{ | ||
var immutableDictBuilder = System.Collections.Immutable.ImmutableDictionary.CreateBuilder<string, AssetOrArchive>(); | ||
immutableDictBuilder.Add(".", new FileArchive(lambdaArchivePath)); | ||
return new Pulumi.AssetArchive(immutableDictBuilder.ToImmutable()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll make htis better so you don't need the ImmutableDict stuff either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct that AssetArchive
is not needed at all in this particular case? Just pass FileArchive
to Code
. Or is there a difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to update this as suggested by @mikhailshilkov
Thanks @CyrusNajmabadi and @mikhailshilkov for helping me get this into shape! |
Simple example that does the toUpper of a string input. This is currently two separate project that require separate build steps. Happy to make updates if someone has knowledge on how to combine them.