Skip to content

Commit

Permalink
improve readme, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBoyle committed Nov 8, 2019
1 parent 5cb06f0 commit 54da577
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 140 deletions.
34 changes: 28 additions & 6 deletions aws-cs-lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# AWS C# Lambda Example
Creates a lambda that does a simple `.toUpper` on the string input and returns it.
# AWS C# Lambda
This example creates a lambda that does a simple `.toUpper` on the string input and returns it.

## Deploying the App

## Instructions
To deploy your infrastructure, follow the below steps.

### Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
2. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)

### Steps

After cloning this repo, from this working directory, run these commands:

1. Build and publish the lambda function, making the output available to our Pulumi program.

From this directory:
```bash
# build publish the lambda function
cd dotnetLambda/src/dotnetLambda/ && dotnet restore && dotnet build && dotnet publish && cd ../../../
```

2. Execute our Pulumi program to archive our published function output, and create our lambda.
```bash
# execute the pulumi program to deploy the lambda
cd ./pulumi/ && pulumi up && cd ../
```

3. Call our lambda function from the aws cli.
```bash
aws lambda invoke \
--function-name $(pulumi stack output lambda) \
--region $(pulumi config get aws:region) \
--payload '"foo"' \
output.json

cat output.json
# "FOO"
```
54 changes: 12 additions & 42 deletions aws-cs-lambda/dotnetLambda/src/dotnetLambda/Readme.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
# AWS Lambda Empty Function Project
# AWS Lambda Starter Function
This starter function takes a string input, and returns the `toUpper` of it.

This starter project consists of:
* Function.cs - class file containing a class with a single function handler method
* aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS
This project must be built and published prior to running `pulumi up` so that our pulumi program can create an [Archive](https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/asset/#Archive).

You may also have a test project depending on the options selected.

The generated function handler is a simple method accepting a string argument that returns the uppercase equivalent of the input string. Replace the body of this method, and parameters, to suit your needs.

## Here are some steps to follow from Visual Studio:

To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*.

To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree.

To perform testing against your deployed function use the Test Invoke tab in the opened Function View window.

To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window.

To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window.

To view execution logs of invocations of your function use the Logs tab in the opened Function View window.

## Here are some steps to follow to get started from the command line:

Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line.

Install Amazon.Lambda.Tools Global Tools if not already installed.
```
dotnet tool install -g Amazon.Lambda.Tools
```bash
dotnet build
dotnet publish
```

If already installed check if new version is available.
```
dotnet tool update -g Amazon.Lambda.Tools
```
See the [AWS .NET Lambda documentation](https://aws.amazon.com/blogs/compute/developing-net-core-aws-lambda-functions/) for more.

Execute unit tests
```
cd "BlueprintBaseName/test/BlueprintBaseName.Tests"
dotnet test
## About
Generated with:
```sh
dotnet new lambda.EmptyFunction
```
See the [AWS .NET Lambda documentation](https://aws.amazon.com/blogs/compute/developing-net-core-aws-lambda-functions/) for more C# templates.

Deploy function to AWS Lambda
```
cd "BlueprintBaseName/src/BlueprintBaseName"
dotnet lambda deploy-function
```

This file was deleted.

28 changes: 0 additions & 28 deletions aws-cs-lambda/dotnetLambda/test/dotnetLambda.Tests/FunctionTest.cs

This file was deleted.

This file was deleted.

62 changes: 34 additions & 28 deletions aws-cs-lambda/pulumi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;

using Pulumi;
using Pulumi.Aws.Lambda;
Expand All @@ -16,36 +17,38 @@ public static Role createLambdaRole()
{
var lambdaRole = new Role("lambdaRole", new RoleArgs
{
AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""Service"": ""lambda.amazonaws.com""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}",
AssumeRolePolicy =
@"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""Service"": ""lambda.amazonaws.com""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}",
});

var logPolicy = new RolePolicy("lambdaLogPolicy", new RolePolicyArgs
{
Role = lambdaRole.Id,
Policy = @"{
""Version"": ""2012-10-17"",
""Statement"": [{
""Effect"": ""Allow"",
""Action"": [
""logs:CreateLogGroup"",
""logs:CreateLogStream"",
""logs:PutLogEvents""
],
""Resource"": ""arn:aws:logs:*:*:*""
}]
}"
Policy =
@"{
""Version"": ""2012-10-17"",
""Statement"": [{
""Effect"": ""Allow"",
""Action"": [
""logs:CreateLogGroup"",
""logs:CreateLogStream"",
""logs:PutLogEvents""
],
""Resource"": ""arn:aws:logs:*:*:*""
}]
}"
});

return lambdaRole;
Expand All @@ -58,14 +61,17 @@ static Task<int> Main()
{
return Deployment.RunAsync(() =>
{
var hnLambda = new Function("HN-Lambda", new FunctionArgs
var lambda = new Function("basicLambda", new FunctionArgs
{
Runtime = "dotnetcore2.1",
Code = LambdaUtil.buildArchive("../dotnetLambda/src/dotnetLambda//bin/Debug/netcoreapp2.1/publish"),
Handler = "dotnetLambda::dotnetLambda.Function::FunctionHandler",
Role = LambdaUtil.createLambdaRole().Arn
});
return new Dictionary<string, object>{
{"lambda", lambda.Arn}
};
});
}
}

4 changes: 2 additions & 2 deletions aws-cs-lambda/pulumi/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: evanDotnetAws
name: lambda
runtime: dotnet
description: A minimal AWS C# Pulumi program
description: Basic example of an AWS lambda using C#

0 comments on commit 54da577

Please sign in to comment.