Skip to content

Commit

Permalink
Adding new code files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlhagerm committed Oct 17, 2023
1 parent 398e35b commit bd14e00
Show file tree
Hide file tree
Showing 25 changed files with 524 additions and 93 deletions.
125 changes: 32 additions & 93 deletions applications/feedback_sentiment_analyzer/cdk/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,110 +214,49 @@ const JAVA_FUNCTIONS: AppFunctionConfig[] = [
},
];

const DOTNET_FUNCTIONS = [
const DOTNET_FUNCTION_CONFIG = {
...BASE_APP_FUNCTION,
runtime: Runtime.DOTNET_6,
codeAsset: () => {
const source = resolve("../../../dotnetv3/cross-service/FeedbackSentimentAnalyzer");
return Code.fromAsset(source, {
bundling: {
command: [
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools" +
" && dotnet build" +
" && cd PamApi" +
" && dotnet lambda package --output-package /asset-output/function.zip",
],
image: Runtime.DOTNET_6.bundlingImage,
user: "root",
outputType: BundlingOutput.ARCHIVED,
},
});
},
};

const DOTNET_FUNCTIONS: AppFunctionConfig[] = [
{
...BASE_APP_FUNCTION,
...DOTNET_FUNCTION_CONFIG,
name: "ExtractText",
handler: "FsaExtractText::FsaExtractText.ExtractTextFunction::FunctionHandler",
runtime: Runtime.DOTNET_6,
codeAsset() {
const source = resolve(
"../../../dotnetv3/cross-service/FeedbackSentimentAnalyzer"
);
return Code.fromAsset(source, {
bundling: {
command: [
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools" +
" && dotnet build" +
" && cd FsaExtractText" +
" && dotnet lambda package --output-package /asset-output/function.zip",
],
image: Runtime.DOTNET_6.bundlingImage,
user: "root",
outputType: BundlingOutput.ARCHIVED,
},
});
},
handler: "com.example.fsa.handlers.ExtractTextHandler::handleRequest",
},
{
...BASE_APP_FUNCTION,
...COMMON_JAVA_FUNCTION_CONFIG,
name: "AnalyzeSentiment",
handler: "FsaAnalyzeSentiment::FsaAnalyzeSentiment.AnalyzeSentimentFunction::FunctionHandler",
runtime: Runtime.DOTNET_6,
codeAsset() {
const source = resolve(
"../../../dotnetv3/cross-service/FeedbackSentimentAnalyzer"
);
return Code.fromAsset(source, {
bundling: {
command: [
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools" +
" && dotnet build" +
" && cd FsaAnalyzeSentiment" +
" && dotnet lambda package --output-package /asset-output/function.zip",
],
image: Runtime.DOTNET_6.bundlingImage,
user: "root",
outputType: BundlingOutput.ARCHIVED,
},
});
},
handler: "com.example.fsa.handlers.AnalyzeSentimentHandler::handleRequest",
},
{
...BASE_APP_FUNCTION,
...COMMON_JAVA_FUNCTION_CONFIG,
name: "TranslateText",
handler: "FsaTranslateText::FsaTranslateText.TranslateTextFunction::FunctionHandler",
runtime: Runtime.DOTNET_6,
codeAsset() {
const source = resolve(
"../../../dotnetv3/cross-service/FeedbackSentimentAnalyzer"
);
return Code.fromAsset(source, {
bundling: {
command: [
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools" +
" && dotnet build" +
" && cd FsaTranslateText" +
" && dotnet lambda package --output-package /asset-output/function.zip",
],
image: Runtime.DOTNET_6.bundlingImage,
user: "root",
outputType: BundlingOutput.ARCHIVED,
},
});
},
handler: "com.example.fsa.handlers.TranslateTextHandler::handleRequest",
},
{
...BASE_APP_FUNCTION,
...COMMON_JAVA_FUNCTION_CONFIG,
name: "SynthesizeAudio",
handler: "FsaSynthesizeAudio::FsaSynthesizeAudio.SynthesizeAudioFunction::FunctionHandler",
runtime: Runtime.DOTNET_6,
codeAsset() {
const source = resolve(
"../../../dotnetv3/cross-service/FeedbackSentimentAnalyzer"
);
return Code.fromAsset(source, {
bundling: {
command: [
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools" +
" && dotnet build" +
" && cd FsaSynthesizeAudio" +
" && dotnet lambda package --output-package /asset-output/function.zip",
],
image: Runtime.DOTNET_6.bundlingImage,
user: "root",
outputType: BundlingOutput.ARCHIVED,
},
});
},
handler: "com.example.fsa.handlers.SynthesizeAudioHandler::handleRequest",
},
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33927.249
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FsaExtractText", "FsaExtractText\FsaExtractText.csproj", "{C0BB9701-7EE8-4A91-B1EB-B3888ED43079}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FsaAnalyzeSentiment", "FsaAnalyzeSentiment\FsaAnalyzeSentiment.csproj", "{9B31C723-D4B0-4953-B5B1-9002E7181DEB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FsaTranslateText", "FsaTranslateText\FsaTranslateText.csproj", "{9886D38A-541E-4BF5-83CE-6CA85088028B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FsaSynthesizeAudio", "FsaSynthesizeAudio\FsaSynthesizeAudio.csproj", "{4613C012-D517-4C57-98A3-F59B727889EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FsaServices", "FsaServices\FsaServices.csproj", "{DA3393CC-DBBF-444E-947C-FBDC4BA66C55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FsaServicesTest", "FsaServicesTest\FsaServicesTest.csproj", "{3A3503C4-9077-4BB3-90C9-08A2B8ED798D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C0BB9701-7EE8-4A91-B1EB-B3888ED43079}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0BB9701-7EE8-4A91-B1EB-B3888ED43079}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0BB9701-7EE8-4A91-B1EB-B3888ED43079}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0BB9701-7EE8-4A91-B1EB-B3888ED43079}.Release|Any CPU.Build.0 = Release|Any CPU
{9B31C723-D4B0-4953-B5B1-9002E7181DEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B31C723-D4B0-4953-B5B1-9002E7181DEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B31C723-D4B0-4953-B5B1-9002E7181DEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B31C723-D4B0-4953-B5B1-9002E7181DEB}.Release|Any CPU.Build.0 = Release|Any CPU
{9886D38A-541E-4BF5-83CE-6CA85088028B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9886D38A-541E-4BF5-83CE-6CA85088028B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9886D38A-541E-4BF5-83CE-6CA85088028B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9886D38A-541E-4BF5-83CE-6CA85088028B}.Release|Any CPU.Build.0 = Release|Any CPU
{4613C012-D517-4C57-98A3-F59B727889EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4613C012-D517-4C57-98A3-F59B727889EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4613C012-D517-4C57-98A3-F59B727889EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4613C012-D517-4C57-98A3-F59B727889EE}.Release|Any CPU.Build.0 = Release|Any CPU
{DA3393CC-DBBF-444E-947C-FBDC4BA66C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA3393CC-DBBF-444E-947C-FBDC4BA66C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA3393CC-DBBF-444E-947C-FBDC4BA66C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA3393CC-DBBF-444E-947C-FBDC4BA66C55}.Release|Any CPU.Build.0 = Release|Any CPU
{3A3503C4-9077-4BB3-90C9-08A2B8ED798D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A3503C4-9077-4BB3-90C9-08A2B8ED798D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A3503C4-9077-4BB3-90C9-08A2B8ED798D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A3503C4-9077-4BB3-90C9-08A2B8ED798D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7E557C4-6C58-4B38-8C84-D71A72BD3F3C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using Amazon.Lambda.Core;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace FsaAnalyzeSentiment;

public class AnalyzeSentimentFunction
{

/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return input.ToUpper();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Generate ready to run images during publishing to improve cold start time. -->
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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": "default",
"region": "us-west-2",
"configuration": "Release",
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "FsaAnalyzeSentiment::FsaAnalyzeSentiment.Function::FunctionHandler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using Amazon.Lambda.Core;
using Amazon.Lambda.S3Events;
using Amazon.S3;
using Amazon.S3.Util;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace FsaExtractText;

public class ExtractTextFunction
{
IAmazonS3 S3Client { get; set; }

/// <summary>
/// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment
/// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the
/// region the Lambda function is executed in.
/// </summary>
public ExtractTextFunction()
{
S3Client = new AmazonS3Client();
}

/// <summary>
/// Constructs an instance with a preconfigured S3 client. This can be used for testing the outside of the Lambda environment.
/// </summary>
/// <param name="s3Client"></param>
public ExtractTextFunction(IAmazonS3 s3Client)
{
this.S3Client = s3Client;
}

/// <summary>
/// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used
/// to respond to S3 notifications.
/// </summary>
/// <param name="evnt"></param>
/// <param name="context"></param>
/// <returns></returns>
public async Task<string?> FunctionHandler(S3Event evnt, ILambdaContext context)
{
var s3Event = evnt.Records?[0].S3;
if (s3Event == null)
{
return null;
}

try
{
var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
return response.Headers.ContentType;
}
catch (Exception e)
{
context.Logger.LogInformation($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
context.Logger.LogInformation(e.Message);
context.Logger.LogInformation(e.StackTrace);
throw;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Generate ready to run images during publishing to improve cold start time. -->
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.S3Events" Version="3.0.1" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
<PackageReference Include="AWSSDK.S3" Version="3.7.205.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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": "default",
"region": "us-west-2",
"configuration": "Release",
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "FsaExtractText::FsaExtractText.Function::FunctionHandler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

namespace FsaServices
{
public class Class1
{

}
}
Loading

0 comments on commit bd14e00

Please sign in to comment.