Skip to content

Commit a4a866b

Browse files
committed
Add SQS Blueprint
1 parent 786e7d9 commit a4a866b

File tree

11 files changed

+253
-2
lines changed

11 files changed

+253
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"display-name":"Simple SQS Function",
3+
"system-name":"SimpleSQSFunction",
4+
"description": "A project for responding to SQS Event notifications",
5+
"sort-order" : 101,
6+
"hidden-tags" : ["C#","LambdaProject"],
7+
"tags":["SQS", "Simple"]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"author": "AWS",
3+
"classifications": ["AWS", "Lambda", "Function"],
4+
"name": "Lambda Simple SQS Function",
5+
"identity": "AWS.Lambda.Simple.SQS.CSharp",
6+
"groupIdentity": "AWS.Lambda.Simple.SQS",
7+
"shortName": "lambda.SQS",
8+
"tags": {
9+
"language": "C#",
10+
"type": "project"
11+
},
12+
"sourceName": "BlueprintBaseName.1",
13+
"preferNameDirectory": true,
14+
"symbols": {
15+
"profile": {
16+
"type": "parameter",
17+
"description" : "The AWS credentials profile set in aws-lambda-tools-defaults.json and used as the default profile when interacting with AWS.",
18+
"datatype": "string",
19+
"replaces" : "DefaultProfile",
20+
"defaultValue": ""
21+
},
22+
"region": {
23+
"type": "parameter",
24+
"description" : "The AWS region set in aws-lambda-tools-defaults.json and used as the default region when interacting with AWS.",
25+
"datatype": "string",
26+
"replaces" : "DefaultRegion",
27+
"defaultValue": ""
28+
},
29+
"safe-sourcename": {
30+
"type": "generated",
31+
"generator": "coalesce",
32+
"parameters": {
33+
"sourceVariableName": "safe_namespace",
34+
"fallbackVariableName": "safe_name"
35+
},
36+
"replaces": "BlueprintBaseName._1"
37+
}
38+
},
39+
"primaryOutputs": [ { "path": "./src/BlueprintBaseName.1/BlueprintBaseName.1.csproj" } ]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
10+
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" />
11+
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="1.0.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.1.4" />
16+
</ItemGroup>
17+
18+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using Amazon.Lambda.Core;
7+
using Amazon.Lambda.SQSEvents;
8+
9+
10+
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
11+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
12+
13+
namespace BlueprintBaseName._1
14+
{
15+
public class Function
16+
{
17+
/// <summary>
18+
/// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment
19+
/// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the
20+
/// region the Lambda function is executed in.
21+
/// </summary>
22+
public Function()
23+
{
24+
25+
}
26+
27+
28+
/// <summary>
29+
/// This method is called for every Lambda invocation. This method takes in an SQS event object and can be used
30+
/// to respond to SQS messages.
31+
/// </summary>
32+
/// <param name="evnt"></param>
33+
/// <param name="context"></param>
34+
/// <returns></returns>
35+
public async Task FunctionHandler(SQSEvent evnt, ILambdaContext context)
36+
{
37+
foreach(var message in evnt.Records)
38+
{
39+
await ProcessMessageAsync(message, context);
40+
}
41+
}
42+
43+
private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context)
44+
{
45+
context.Logger.LogLine($"Processed message {message.Body}");
46+
47+
// TODO: Do interesting based on the new message
48+
await Task.CompletedTask;
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# AWS Lambda Simple SQS Function Project
2+
3+
This starter project consists of:
4+
* Function.cs - class file containing a class with a single function handler method
5+
* aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS
6+
7+
You may also have a test project depending on the options selected.
8+
9+
The generated function handler responds to events on an Amazon SQS queue. The handler receives the bucket and object key details in an SQSEvent instance and returns the content type of the object as the function output. Replace the body of this method, and parameters, to suit your needs.
10+
11+
After deploying your function you must configure an Amazon SQS queue as an event source to trigger your Lambda function.
12+
13+
## Here are some steps to follow from Visual Studio:
14+
15+
To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*.
16+
17+
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.
18+
19+
To perform testing against your deployed function use the Test Invoke tab in the opened Function View window.
20+
21+
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.
22+
23+
To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window.
24+
25+
To view execution logs of invocations of your function use the Logs tab in the opened Function View window.
26+
27+
## Here are some steps to follow to get started from the command line:
28+
29+
Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *BlueprintBaseName.1*):
30+
31+
Restore dependencies
32+
```
33+
cd "BlueprintBaseName.1"
34+
dotnet restore
35+
```
36+
37+
Execute unit tests
38+
```
39+
cd "BlueprintBaseName.1/test/BlueprintBaseName.1.Tests"
40+
dotnet test
41+
```
42+
43+
Deploy function to AWS Lambda
44+
```
45+
cd "BlueprintBaseName.1/src/BlueprintBaseName.1"
46+
dotnet lambda deploy-function
47+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"Information": [
3+
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
4+
"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.",
5+
6+
"dotnet lambda help",
7+
8+
"All the command line options for the Lambda command can be specified in this file."
9+
],
10+
11+
"profile":"DefaultProfile",
12+
"region" : "DefaultRegion",
13+
"configuration": "Release",
14+
"framework": "netcoreapp2.0",
15+
"function-runtime": "dotnetcore2.0",
16+
"function-memory-size": 256,
17+
"function-timeout": 30,
18+
"function-handler": "BlueprintBaseName.1::BlueprintBaseName._1.Function::FunctionHandler"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
9+
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
10+
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="1.0.0" />
11+
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="1.0.0" />
12+
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
14+
<PackageReference Include="xunit" Version="2.3.1" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\..\src\BlueprintBaseName.1\BlueprintBaseName.1.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
using Xunit;
7+
using Amazon.Lambda.TestUtilities;
8+
using Amazon.Lambda.SQSEvents;
9+
10+
using BlueprintBaseName._1;
11+
12+
namespace BlueprintBaseName._1.Tests
13+
{
14+
public class FunctionTest
15+
{
16+
[Fact]
17+
public async Task TestSQSEventLambdaFunction()
18+
{
19+
var sqsEvent = new SQSEvent
20+
{
21+
Records = new List<SQSEvent.SQSMessage>
22+
{
23+
new SQSEvent.SQSMessage
24+
{
25+
Body = "foobar"
26+
}
27+
}
28+
};
29+
30+
var logger = new TestLambdaLogger();
31+
var context = new TestLambdaContext
32+
{
33+
Logger = logger
34+
};
35+
36+
var function = new Function();
37+
await function.FunctionHandler(sqsEvent, context);
38+
39+
Assert.Contains("Processed message foobar", logger.Buffer.ToString());
40+
}
41+
}
42+
}

Blueprints/BlueprintDefinitions/Msbuild-NETCore_2_0/template.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>Amazon.Lambda.Templates</id>
5-
<version>3.0.0</version>
5+
<version>3.1.0</version>
66
<authors>Amazon Web Services</authors>
77
<tags>AWS Amazon Lambda</tags>
88
<description>AWS Lambda templates for Microsoft Template Engine accessible with the dotnet CLI's new command</description>

Libraries/src/Amazon.Lambda.Serialization.Json/Amazon.Lambda.Serialization.Json.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AssemblyName>Amazon.Lambda.Serialization.Json</AssemblyName>
1212
<PackageId>Amazon.Lambda.Serialization.Json</PackageId>
1313
<PackageTags>AWS;Amazon;Lambda</PackageTags>
14-
<Version>1.2.1</Version>
14+
<Version>1.3.0</Version>
1515
</PropertyGroup>
1616

1717
<ItemGroup>

buildtools/build.proj

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@
143143
Projects="$(MSBuildProjectFile)"
144144
Targets="run-blueprint-dotnetnew"
145145
Properties="TemplateName=serverless.S3;ProjectName=S3FunctionServerlessF;Lang=F#"/>
146+
<MSBuild
147+
Projects="$(MSBuildProjectFile)"
148+
Targets="run-blueprint-dotnetnew"
149+
Properties="TemplateName=lambda.SQS;ProjectName=SQSFunctionC;Lang=C#"/>
146150
<MSBuild
147151
Projects="$(MSBuildProjectFile)"
148152
Targets="run-blueprint-dotnetnew"

0 commit comments

Comments
 (0)