diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index dbb5ca59..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5509140f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.DS_Store diff --git a/sample-apps/blank-csharp-with-layer/README.md b/sample-apps/blank-csharp-with-layer/README.md index eac563d9..638db2da 100644 --- a/sample-apps/blank-csharp-with-layer/README.md +++ b/sample-apps/blank-csharp-with-layer/README.md @@ -1,93 +1,93 @@ -# Blank function with layer (C#) - -![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png) - -The project source includes function code and supporting resources: - -- `src/blank-csharp` - A C# .NET Core function. -- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. - -Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see [Managing Spot Instance Requests](https://docs.aws.amazon.com/lambda/latest/dg/services-ec2-tutorial.html) in the developer guide. - -# Requirements -- [.NET Core SDK 6.0](https://dotnet.microsoft.com/download/dotnet-core/6.0) -- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli). Specifically, ensure that you have [Amazon.Lambda.Tools](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) installed. -- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. -- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. - -# Setup -Download or clone this repository. - - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git - $ cd aws-lambda-developer-guide/sample-apps/blank-csharp - -To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`. - - blank-csharp$ ./1-create-bucket.sh - make_bucket: lambda-artifacts-d7aec9f2022ef2b4 - make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer - { - "Role": { - "Path": "/", - "RoleName": "blank-csharp-role", - "RoleId": "AROA6HOIFXAKKWARP5RSC", - "Arn": "arn:aws:iam::978061735956:role/blank-csharp-role", - "CreateDate": "2023-08-22T18:12:29+00:00", - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "sts:AssumeRole" - ], - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - } - -To build a Lambda layer that contains the function's runtime dependencies, run `2-build-layer.sh`. This also uploads the layer to an S3 bucket created by the first script. - - blank-csharp$ ./2-build-layer.sh - -# Deploy -To deploy the application, run `3-deploy.sh`. - - blank-csharp$ ./3-deploy.sh - Amazon Lambda Tools for .NET Core applications (5.8.0) - ... - Created publish archive ... - Creating new Lambda function blank-csharp - New Lambda function created - -This script uses the .NET Amazon Lambda Tools to deploy the Lambda function. It uses the default settings from the `src/aws-lambda-tools-defaults.json` file. - -To invoke the function, run `4-invoke.sh`. - - blank-csharp$ ./4-invoke.sh - { - "StatusCode": 200, - "ExecutedVersion": "$LATEST" - } - {"FunctionCount":13,"TotalCodeSize":598094248} - -Let the script invoke the function a few times and then press `CRTL+C` to exit. - -The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. The following service map shows the function managing spot instances in Amazon EC2. - -![Service Map](/sample-apps/blank-csharp-with-layer/images/blank-csharp-servicemap.png) - -Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function. - -![Trace](/sample-apps/blank-csharp-with-layer/images/blank-csharp-trace.png) - -# Cleanup -To delete the application, run the cleanup script. - - blank-csharp$ ./5-cleanup.sh +# Blank function with layer (C#) + +![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png) + +The project source includes function code and supporting resources: + +- `src/blank-csharp` - A C# .NET Core function. +- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. + +Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see [Managing Spot Instance Requests](https://docs.aws.amazon.com/lambda/latest/dg/services-ec2-tutorial.html) in the developer guide. + +# Requirements +- [.NET Core SDK 8.0](https://dotnet.microsoft.com/download/dotnet-core/8.0) +- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli). Specifically, ensure that you have [Amazon.Lambda.Tools](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) installed. +- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. +- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. + +# Setup +Download or clone this repository. + + $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git + $ cd aws-lambda-developer-guide/sample-apps/blank-csharp + +To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`. + + blank-csharp$ ./1-create-bucket.sh + make_bucket: lambda-artifacts-d7aec9f2022ef2b4 + make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer + { + "Role": { + "Path": "/", + "RoleName": "blank-csharp-role", + "RoleId": "AROA6HOIFXAKKWARP5RSC", + "Arn": "arn:aws:iam::978061735956:role/blank-csharp-role", + "CreateDate": "2023-08-22T18:12:29+00:00", + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "sts:AssumeRole" + ], + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + } + +To build a Lambda layer that contains the function's runtime dependencies, run `2-build-layer.sh`. This also uploads the layer to an S3 bucket created by the first script. + + blank-csharp$ ./2-build-layer.sh + +# Deploy +To deploy the application, run `3-deploy.sh`. + + blank-csharp$ ./3-deploy.sh + Amazon Lambda Tools for .NET Core applications (5.8.0) + ... + Created publish archive ... + Creating new Lambda function blank-csharp + New Lambda function created + +This script uses the .NET Amazon Lambda Tools to deploy the Lambda function. It uses the default settings from the `src/aws-lambda-tools-defaults.json` file. + +To invoke the function, run `4-invoke.sh`. + + blank-csharp$ ./4-invoke.sh + { + "StatusCode": 200, + "ExecutedVersion": "$LATEST" + } + {"FunctionCount":13,"TotalCodeSize":598094248} + +Let the script invoke the function a few times and then press `CRTL+C` to exit. + +The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. The following service map shows the function managing spot instances in Amazon EC2. + +![Service Map](/sample-apps/blank-csharp-with-layer/images/blank-csharp-servicemap.png) + +Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function. + +![Trace](/sample-apps/blank-csharp-with-layer/images/blank-csharp-trace.png) + +# Cleanup +To delete the application, run the cleanup script. + + blank-csharp$ ./5-cleanup.sh \ No newline at end of file diff --git a/sample-apps/blank-csharp-with-layer/src/blank-csharp/aws-lambda-tools-defaults.json b/sample-apps/blank-csharp-with-layer/src/blank-csharp/aws-lambda-tools-defaults.json index 9a237927..1149f222 100644 --- a/sample-apps/blank-csharp-with-layer/src/blank-csharp/aws-lambda-tools-defaults.json +++ b/sample-apps/blank-csharp-with-layer/src/blank-csharp/aws-lambda-tools-defaults.json @@ -1,20 +1,20 @@ -{ - "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-east-1", - "configuration" : "Release", - "framework" : "net6.0", - "function-runtime":"dotnet6", - "function-memory-size" : 512, - "function-timeout" : 30, - "function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler", - "function-role" : "blank-csharp-role" -} +{ + "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-east-1", + "configuration" : "Release", + "framework" : "net8.0", + "function-runtime":"dotnet8", + "function-memory-size" : 512, + "function-timeout" : 30, + "function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler", + "function-role" : "blank-csharp-role" +} diff --git a/sample-apps/blank-csharp-with-layer/src/blank-csharp/blank-csharp.csproj b/sample-apps/blank-csharp-with-layer/src/blank-csharp/blank-csharp.csproj index aa648b33..4e36256f 100644 --- a/sample-apps/blank-csharp-with-layer/src/blank-csharp/blank-csharp.csproj +++ b/sample-apps/blank-csharp-with-layer/src/blank-csharp/blank-csharp.csproj @@ -1,16 +1,16 @@ - - - net6.0 - true - Lambda - - - - - - - - - - + + + net8.0 + true + Lambda + + + + + + + + + + \ No newline at end of file diff --git a/sample-apps/blank-csharp/README.md b/sample-apps/blank-csharp/README.md index ad905416..a731ea2c 100644 --- a/sample-apps/blank-csharp/README.md +++ b/sample-apps/blank-csharp/README.md @@ -1,66 +1,66 @@ -# Blank function (C#) - -![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png) - -The project source includes function code and supporting resources: - -- `src/blank-csharp` - A C# .NET Core function. -- `template.yml` - An AWS CloudFormation template that creates an application. -- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. - -Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see [Managing Spot Instance Requests](https://docs.aws.amazon.com/lambda/latest/dg/services-ec2-tutorial.html) in the developer guide. - -# Requirements -- [.NET Core SDK 6.0](https://dotnet.microsoft.com/download/dotnet-core/6.0) -- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli) -- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. -- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. - -# Setup -Download or clone this repository. - - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git - $ cd aws-lambda-developer-guide/sample-apps/blank-csharp - -To create a new bucket for deployment artifacts, run `1-create-bucket.sh`. - - blank-csharp$ ./1-create-bucket.sh - make_bucket: lambda-artifacts-a5e491dbb5b22e0d - -# Deploy -To deploy the application, run `2-deploy.sh`. - - blank-csharp$ ./2-deploy.sh - Amazon Lambda Tools for .NET Core applications (4.0.0) - Executing publish command - Uploading to e678bc216e6a0d510d661ca9ae2fd941 1009985 / 1009985.0 (100.00%) - Successfully packaged artifacts and wrote output template to file out.yml. - Waiting for changeset to be created.. - Waiting for stack create/update to complete - Successfully created/updated stack - blank-csharp - -This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code. - -To invoke the function, run `3-invoke.sh`. - - blank-csharp$ ./3-invoke.sh - { - "StatusCode": 200, - "ExecutedVersion": "$LATEST" - } - {"FunctionCount":43,"TotalCodeSize":362867335} - -Let the script invoke the function a few times and then press `CRTL+C` to exit. - -The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. The following service map shows the function managing spot instances in Amazon EC2. - -![Service Map](/sample-apps/blank-csharp/images/blank-csharp-servicemap.png) - -Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function. - -![Trace](/sample-apps/blank-csharp/images/blank-csharp-trace.png) - -# Cleanup -To delete the application, run the cleanup script. - - blank-csharp$ ./4-cleanup.sh +# Blank function (C#) + +![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png) + +The project source includes function code and supporting resources: + +- `src/blank-csharp` - A C# .NET Core function. +- `template.yml` - An AWS CloudFormation template that creates an application. +- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. + +Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see [Managing Spot Instance Requests](https://docs.aws.amazon.com/lambda/latest/dg/services-ec2-tutorial.html) in the developer guide. + +# Requirements +- [.NET Core SDK 8.0](https://dotnet.microsoft.com/download/dotnet-core/8.0) +- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli) +- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. +- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. + +# Setup +Download or clone this repository. + + $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git + $ cd aws-lambda-developer-guide/sample-apps/blank-csharp + +To create a new bucket for deployment artifacts, run `1-create-bucket.sh`. + + blank-csharp$ ./1-create-bucket.sh + make_bucket: lambda-artifacts-a5e491dbb5b22e0d + +# Deploy +To deploy the application, run `2-deploy.sh`. + + blank-csharp$ ./2-deploy.sh + Amazon Lambda Tools for .NET Core applications (4.0.0) + Executing publish command + Uploading to e678bc216e6a0d510d661ca9ae2fd941 1009985 / 1009985.0 (100.00%) + Successfully packaged artifacts and wrote output template to file out.yml. + Waiting for changeset to be created.. + Waiting for stack create/update to complete + Successfully created/updated stack - blank-csharp + +This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code. + +To invoke the function, run `3-invoke.sh`. + + blank-csharp$ ./3-invoke.sh + { + "StatusCode": 200, + "ExecutedVersion": "$LATEST" + } + {"FunctionCount":43,"TotalCodeSize":362867335} + +Let the script invoke the function a few times and then press `CRTL+C` to exit. + +The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. The following service map shows the function managing spot instances in Amazon EC2. + +![Service Map](/sample-apps/blank-csharp/images/blank-csharp-servicemap.png) + +Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function. + +![Trace](/sample-apps/blank-csharp/images/blank-csharp-trace.png) + +# Cleanup +To delete the application, run the cleanup script. + + blank-csharp$ ./4-cleanup.sh \ No newline at end of file diff --git a/sample-apps/blank-csharp/src/blank-csharp/aws-lambda-tools-defaults.json b/sample-apps/blank-csharp/src/blank-csharp/aws-lambda-tools-defaults.json index c815dcf9..8a9c7869 100644 --- a/sample-apps/blank-csharp/src/blank-csharp/aws-lambda-tools-defaults.json +++ b/sample-apps/blank-csharp/src/blank-csharp/aws-lambda-tools-defaults.json @@ -1,19 +1,19 @@ -{ - "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-east-2", - "configuration" : "Release", - "framework" : "net6.0", - "function-runtime":"dotnet6", - "function-memory-size" : 512, - "function-timeout" : 30, - "function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler" -} +{ + "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-east-2", + "configuration" : "Release", + "framework" : "net8.0", + "function-runtime":"dotnet8", + "function-memory-size" : 512, + "function-timeout" : 30, + "function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler" +} \ No newline at end of file diff --git a/sample-apps/blank-csharp/src/blank-csharp/blank-csharp.csproj b/sample-apps/blank-csharp/src/blank-csharp/blank-csharp.csproj index aa648b33..4e36256f 100644 --- a/sample-apps/blank-csharp/src/blank-csharp/blank-csharp.csproj +++ b/sample-apps/blank-csharp/src/blank-csharp/blank-csharp.csproj @@ -1,16 +1,16 @@ - - - net6.0 - true - Lambda - - - - - - - - - - + + + net8.0 + true + Lambda + + + + + + + + + + \ No newline at end of file diff --git a/sample-apps/blank-csharp/template.yml b/sample-apps/blank-csharp/template.yaml similarity index 80% rename from sample-apps/blank-csharp/template.yml rename to sample-apps/blank-csharp/template.yaml index 17836497..c92e6a35 100644 --- a/sample-apps/blank-csharp/template.yml +++ b/sample-apps/blank-csharp/template.yaml @@ -1,19 +1,19 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: An AWS Lambda application that calls the Lambda API. -Resources: - function: - Type: AWS::Serverless::Function - Properties: - Handler: blank-csharp::blankCsharp.Function::FunctionHandler - Runtime: dotnetcore3.1 - CodeUri: src/blank-csharp/bin/Release/netcoreapp3.1/blank-csharp.zip - Description: Call the AWS Lambda API - MemorySize: 256 - Timeout: 9 - # Function's execution role - Policies: - - AWSLambdaBasicExecutionRole - - AWSLambda_ReadOnlyAccess - - AWSXrayWriteOnlyAccess - Tracing: Active +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Description: An AWS Lambda application that calls the Lambda API. +Resources: + function: + Type: AWS::Serverless::Function + Properties: + Handler: blank-csharp::blankCsharp.Function::FunctionHandler + Runtime: dotnet8 + CodeUri: src/blank-csharp/bin/Release/net8.0/blank-csharp.zip + Description: Call the AWS Lambda API + MemorySize: 256 + Timeout: 9 + # Function's execution role + Policies: + - AWSLambdaBasicExecutionRole + - AWSLambda_ReadOnlyAccess + - AWSXrayWriteOnlyAccess + Tracing: Active \ No newline at end of file diff --git a/sample-apps/blank-python/README.md b/sample-apps/blank-python/README.md index 52ae49f0..98d059b2 100644 --- a/sample-apps/blank-python/README.md +++ b/sample-apps/blank-python/README.md @@ -11,29 +11,35 @@ The project source includes function code and supporting resources: Use the following instructions to deploy the sample application. # Requirements -- [Python 3.7](https://www.python.org/downloads/). Sample also works with Python 3.8 and 3.9. +- [Python 3.11](https://www.python.org/downloads/). Sample also works with Python 3.9. - The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. - [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. # Setup Download or clone this repository. - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git - $ cd aws-lambda-developer-guide/sample-apps/blank-python + git clone https://github.com/awsdocs/aws-lambda-developer-guide.git + cd aws-lambda-developer-guide/sample-apps/blank-python To create a new bucket for deployment artifacts, run `1-create-bucket.sh`. - blank-python$ ./1-create-bucket.sh + ./1-create-bucket.sh + +Example output: + make_bucket: lambda-artifacts-a5e491dbb5b22e0d To build a Lambda layer that contains the function's runtime dependencies, run `2-build-layer.sh`. Packaging dependencies in a layer reduces the size of the deployment package that you upload when you modify your code. - blank-python$ ./2-build-layer.sh + ./2-build-layer.sh # Deploy To deploy the application, run `3-deploy.sh`. - blank-python$ ./3-deploy.sh + ./3-deploy.sh + +Example output: + Uploading to e678bc216e6a0d510d661ca9ae2fd941 9519118 / 9519118.0 (100.00%) Successfully packaged artifacts and wrote output template to file out.yml. Waiting for changeset to be created.. @@ -45,7 +51,10 @@ This script uses AWS CloudFormation to deploy the Lambda functions and an IAM ro # Test To invoke the function, run `4-invoke.sh`. - blank-python$ ./4-invoke.sh + ./4-invoke.sh + +Example output: + { "StatusCode": 200, "ExecutedVersion": "$LATEST" @@ -65,4 +74,4 @@ Choose a node in the main function graph. Then choose **View traces** to see a l # Cleanup To delete the application, run `5-cleanup.sh`. - blank-python$ ./5-cleanup.sh + ./5-cleanup.sh \ No newline at end of file diff --git a/sample-apps/blank-python/template.yml b/sample-apps/blank-python/template.yml index d2b27aee..dc5024a6 100644 --- a/sample-apps/blank-python/template.yml +++ b/sample-apps/blank-python/template.yml @@ -6,7 +6,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: lambda_function.lambda_handler - Runtime: python3.8 + Runtime: python3.11 CodeUri: function/. Description: Call the AWS Lambda API Timeout: 10 @@ -25,4 +25,4 @@ Resources: Description: Dependencies for the blank-python sample app. ContentUri: package/. CompatibleRuntimes: - - python3.8 + - python3.11 \ No newline at end of file diff --git a/sample-apps/example-csharp/ExampleCS/src/ExampleCS/ExampleCS.csproj b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/ExampleCS.csproj new file mode 100644 index 00000000..a57cd339 --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/ExampleCS.csproj @@ -0,0 +1,18 @@ + + + net8.0 + enable + enable + true + Lambda + + true + + true + + + + + + + \ No newline at end of file diff --git a/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Function.cs b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Function.cs new file mode 100644 index 00000000..b1142dba --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Function.cs @@ -0,0 +1,68 @@ +using System; +using System.Text; +using System.Threading.Tasks; +using Amazon.Lambda.Core; +using Amazon.S3; +using Amazon.S3.Model; + +// Assembly attribute to enable Lambda function logging +[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] + +namespace ExampleLambda; + +public class Order +{ + public string OrderId { get; set; } = string.Empty; + public double Amount { get; set; } + public string Item { get; set; } = string.Empty; +} + +public class OrderHandler +{ + private static readonly AmazonS3Client s3Client = new(); + + public async Task HandleRequest(Order order, ILambdaContext context) + { + try + { + string? bucketName = Environment.GetEnvironmentVariable("RECEIPT_BUCKET"); + if (string.IsNullOrWhiteSpace(bucketName)) + { + throw new ArgumentException("RECEIPT_BUCKET environment variable is not set"); + } + + string receiptContent = $"OrderID: {order.OrderId}\nAmount: ${order.Amount:F2}\nItem: {order.Item}"; + string key = $"receipts/{order.OrderId}.txt"; + + await UploadReceiptToS3(bucketName, key, receiptContent); + + context.Logger.LogInformation($"Successfully processed order {order.OrderId} and stored receipt in S3 bucket {bucketName}"); + return "Success"; + } + catch (Exception ex) + { + context.Logger.LogError($"Failed to process order: {ex.Message}"); + throw; + } + } + + private async Task UploadReceiptToS3(string bucketName, string key, string receiptContent) + { + try + { + var putRequest = new PutObjectRequest + { + BucketName = bucketName, + Key = key, + ContentBody = receiptContent, + ContentType = "text/plain" + }; + + await s3Client.PutObjectAsync(putRequest); + } + catch (AmazonS3Exception ex) + { + throw new Exception($"Failed to upload receipt to S3: {ex.Message}", ex); + } + } +} diff --git a/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Readme.md b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Readme.md new file mode 100644 index 00000000..422393ec --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/Readme.md @@ -0,0 +1,49 @@ +# AWS Lambda Empty Function Project + +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 + +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 +``` + +If already installed check if new version is available. +``` + dotnet tool update -g Amazon.Lambda.Tools +``` + +Execute unit tests +``` + cd "ExampleCS/test/ExampleCS.Tests" + dotnet test +``` + +Deploy function to AWS Lambda +``` + cd "ExampleCS/src/ExampleCS" + dotnet lambda deploy-function +``` diff --git a/sample-apps/example-csharp/ExampleCS/src/ExampleCS/aws-lambda-tools-defaults.json b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/aws-lambda-tools-defaults.json new file mode 100644 index 00000000..a9757798 --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/src/ExampleCS/aws-lambda-tools-defaults.json @@ -0,0 +1,16 @@ +{ + "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-east-1", + "configuration": "Release", + "function-architecture": "x86_64", + "function-runtime": "dotnet8", + "function-memory-size": 512, + "function-timeout": 30, + "function-handler": "ExampleCS::ExampleLambda.OrderHandler::HandleRequest" +} \ No newline at end of file diff --git a/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/ExampleCS.Tests.csproj b/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/ExampleCS.Tests.csproj new file mode 100644 index 00000000..4aa7182a --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/ExampleCS.Tests.csproj @@ -0,0 +1,18 @@ + + + net8.0 + enable + enable + true + + + + + + + + + + + + \ No newline at end of file diff --git a/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/FunctionTest.cs b/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/FunctionTest.cs new file mode 100644 index 00000000..07640759 --- /dev/null +++ b/sample-apps/example-csharp/ExampleCS/test/ExampleCS.Tests/FunctionTest.cs @@ -0,0 +1,20 @@ +using Xunit; +using Amazon.Lambda.Core; +using Amazon.Lambda.TestUtilities; + +namespace ExampleCS.Tests; + +public class FunctionTest +{ + [Fact] + public void TestToUpperFunction() + { + + // Invoke the lambda function and confirm the string was upper cased. + var function = new Function(); + var context = new TestLambdaContext(); + var upperCase = function.FunctionHandler("hello world", context); + + Assert.Equal("HELLO WORLD", upperCase); + } +} diff --git a/sample-apps/example-java/function/build.gradle b/sample-apps/example-java/function/build.gradle new file mode 100644 index 00000000..ab6730c9 --- /dev/null +++ b/sample-apps/example-java/function/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'java' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.amazonaws:aws-lambda-java-core:1.2.3' + implementation 'software.amazon.awssdk:s3:2.28.29' + implementation 'org.slf4j:slf4j-nop:2.0.16' +} + +task buildZip(type: Zip) { + from compileJava + from processResources + into('lib') { + from configurations.runtimeClasspath + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + +build.dependsOn buildZip diff --git a/sample-apps/java17-examples/pom.xml b/sample-apps/example-java/function/pom.xml similarity index 61% rename from sample-apps/java17-examples/pom.xml rename to sample-apps/example-java/function/pom.xml index 73a9fcf7..72c3b301 100644 --- a/sample-apps/java17-examples/pom.xml +++ b/sample-apps/example-java/function/pom.xml @@ -2,37 +2,30 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.example - java17-examples + example-java jar 1.0-SNAPSHOT - java17-examples-function + example-java-function UTF-8 - 17 - 17 + 21 + 21 - com.amazonaws - aws-lambda-java-core - 1.2.1 + com.amazonaws + aws-lambda-java-core + 1.2.3 - org.slf4j - slf4j-nop - 2.0.6 + software.amazon.awssdk + s3 + 2.28.29 - org.junit.jupiter - junit-jupiter-api - 5.8.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.8.2 - test + org.slf4j + slf4j-nop + 2.0.16 @@ -40,22 +33,20 @@ maven-surefire-plugin - 2.22.2 + 3.5.2 org.apache.maven.plugins maven-shade-plugin - 3.2.2 + 3.4.1 false *:* - module-info.class META-INF/* META-INF/versions/** - META-INF/services/** @@ -72,10 +63,9 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 - 17 - 17 + 21 diff --git a/sample-apps/example-java/function/src/main/java/example/OrderHandler.java b/sample-apps/example-java/function/src/main/java/example/OrderHandler.java new file mode 100644 index 00000000..df50eef0 --- /dev/null +++ b/sample-apps/example-java/function/src/main/java/example/OrderHandler.java @@ -0,0 +1,64 @@ +package example; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.PutObjectRequest; +import software.amazon.awssdk.services.s3.model.S3Exception; + +import java.nio.charset.StandardCharsets; + +/** + * Lambda handler for processing orders and storing receipts in S3. + */ +public class OrderHandler implements RequestHandler { + + private static final S3Client S3_CLIENT = S3Client.builder().build(); + + /** + * Record to model the input event. + */ + public record Order(String orderId, double amount, String item) {} + + @Override + public String handleRequest(Order event, Context context) { + try { + // Access environment variables + String bucketName = System.getenv("RECEIPT_BUCKET"); + if (bucketName == null || bucketName.isEmpty()) { + throw new IllegalArgumentException("RECEIPT_BUCKET environment variable is not set"); + } + + // Create the receipt content and key destination + String receiptContent = String.format("OrderID: %s\nAmount: $%.2f\nItem: %s", + event.orderId(), event.amount(), event.item()); + String key = "receipts/" + event.orderId() + ".txt"; + + // Upload the receipt to S3 + uploadReceiptToS3(bucketName, key, receiptContent); + + context.getLogger().log("Successfully processed order " + event.orderId() + + " and stored receipt in S3 bucket " + bucketName); + return "Success"; + + } catch (Exception e) { + context.getLogger().log("Failed to process order: " + e.getMessage()); + throw new RuntimeException(e); + } + } + + private void uploadReceiptToS3(String bucketName, String key, String receiptContent) { + try { + PutObjectRequest putObjectRequest = PutObjectRequest.builder() + .bucket(bucketName) + .key(key) + .build(); + + // Convert the receipt content to bytes and upload to S3 + S3_CLIENT.putObject(putObjectRequest, RequestBody.fromBytes(receiptContent.getBytes(StandardCharsets.UTF_8))); + } catch (S3Exception e) { + throw new RuntimeException("Failed to upload receipt to S3: " + e.awsErrorDetails().errorMessage(), e); + } + } +} diff --git a/sample-apps/java-events-v1sdk/1-create-bucket.sh b/sample-apps/java-events-v1sdk/1-create-bucket.sh deleted file mode 100755 index 64a5f749..00000000 --- a/sample-apps/java-events-v1sdk/1-create-bucket.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -BUCKET_ID=$(dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n') -BUCKET_NAME=lambda-artifacts-$BUCKET_ID -echo $BUCKET_NAME > bucket-name.txt -aws s3 mb s3://$BUCKET_NAME diff --git a/sample-apps/java-events-v1sdk/2-build-layer.sh b/sample-apps/java-events-v1sdk/2-build-layer.sh deleted file mode 100755 index 9f038396..00000000 --- a/sample-apps/java-events-v1sdk/2-build-layer.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -eo pipefail -gradle -q packageLibs -mv build/distributions/java-events-v1sdk.zip build/java-events-v1sdk-lib.zip \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/3-deploy.sh b/sample-apps/java-events-v1sdk/3-deploy.sh deleted file mode 100755 index 5ce8d160..00000000 --- a/sample-apps/java-events-v1sdk/3-deploy.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -eo pipefail -ARTIFACT_BUCKET=$(cat bucket-name.txt) -TEMPLATE=template.yml -if [ $1 ] -then - if [ $1 = mvn ] - then - TEMPLATE=template-mvn.yml - mvn package - fi -else - gradle build -i -fi -aws cloudformation package --template-file $TEMPLATE --s3-bucket $ARTIFACT_BUCKET --output-template-file out.yml -aws cloudformation deploy --template-file out.yml --stack-name java-events-v1sdk --capabilities CAPABILITY_NAMED_IAM diff --git a/sample-apps/java-events-v1sdk/4-invoke.sh b/sample-apps/java-events-v1sdk/4-invoke.sh deleted file mode 100755 index 05ddd9f8..00000000 --- a/sample-apps/java-events-v1sdk/4-invoke.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -set -eo pipefail -FUNCTION=$(aws cloudformation describe-stack-resource --stack-name java-events-v1sdk --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) -if [ $1 ] -then - case $1 in - ddb) - PAYLOAD='fileb://events/dynamodb-record.json' - ;; - kin) - PAYLOAD='fileb://events/kinesis-record.json' - ;; - *) - echo -n "Unknown event type" - ;; - esac -fi -while true; do - if [ $PAYLOAD ] - then - aws lambda invoke --function-name $FUNCTION --payload $PAYLOAD out.json - else - aws lambda invoke --function-name $FUNCTION --payload fileb://event.json out.json - fi - cat out.json - echo "" - sleep 2 -done diff --git a/sample-apps/java-events-v1sdk/5-cleanup.sh b/sample-apps/java-events-v1sdk/5-cleanup.sh deleted file mode 100755 index 79b326e4..00000000 --- a/sample-apps/java-events-v1sdk/5-cleanup.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -set -eo pipefail -STACK=java-events-v1sdk -if [[ $# -eq 1 ]] ; then - STACK=$1 - echo "Deleting stack $STACK" -fi -FUNCTION=$(aws cloudformation describe-stack-resource --stack-name $STACK --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) -aws cloudformation delete-stack --stack-name $STACK -echo "Deleted $STACK stack." - -if [ -f bucket-name.txt ]; then - ARTIFACT_BUCKET=$(cat bucket-name.txt) - if [[ ! $ARTIFACT_BUCKET =~ lambda-artifacts-[a-z0-9]{16} ]] ; then - echo "Bucket was not created by this application. Skipping." - else - while true; do - read -p "Delete deployment artifacts and bucket ($ARTIFACT_BUCKET)? (y/n)" response - case $response in - [Yy]* ) aws s3 rb --force s3://$ARTIFACT_BUCKET; rm bucket-name.txt; break;; - [Nn]* ) break;; - * ) echo "Response must start with y or n.";; - esac - done - fi -fi - -while true; do - read -p "Delete function log group (/aws/lambda/$FUNCTION)? (y/n)" response - case $response in - [Yy]* ) aws logs delete-log-group --log-group-name /aws/lambda/$FUNCTION; break;; - [Nn]* ) break;; - * ) echo "Response must start with y or n.";; - esac -done - -rm -f out.yml out.json -rm -rf build .gradle target diff --git a/sample-apps/java-events-v1sdk/README.md b/sample-apps/java-events-v1sdk/README.md deleted file mode 100644 index 6405882d..00000000 --- a/sample-apps/java-events-v1sdk/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# Basic function with event library types and the AWS SDK (Java) - -This sample application shows the use of the `aws-lambda-java-events` library with event types that require AWS SDK as a dependency. A separate handler class is defined for each input type. For other event types (which don't require the AWS SDK), see the `java-events` sample. - -**Note: The `java-events-v1sdk` examples are deprecated.** As of version 3.0.0 of the `aws-lambda-java-events` package, [users are no longer required to pull in SDK dependencies in order to use that library](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events). Please see the [`java-events` package](https://github.com/awsdocs/aws-lambda-developer-guide/tree/main/sample-apps/java-events) for updated examples. - -![Architecture](/sample-apps/java-events-v1sdk/images/sample-java-events-v1sdk.png) - -The project includes function code and supporting resources: -- `src/main` - A Java function. -- `src/test` - A unit test and helper classes. -- `template.yml` - An AWS CloudFormation template that creates an application. -- `build.gradle` - A Gradle build file. -- `pom.xml` - A Maven build file. -- `1-create-bucket.sh`, `2-build-layer.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. - -Use the following instructions to deploy the sample application. - -# Requirements -- [Java 8 runtime environment (SE JRE)](https://www.oracle.com/java/technologies/javase-downloads.html) -- [Gradle 5](https://gradle.org/releases/) or [Maven 3](https://maven.apache.org/docs/history.html) -- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. -- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. - -# Setup -Download or clone this repository. - - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git - $ cd aws-lambda-developer-guide/sample-apps/java-events-v1sdk - -Run `1-create-bucket.sh` to create a new bucket for deployment artifacts. - - java-events-v1sdk$ ./1-create-bucket.sh - make_bucket: lambda-artifacts-a5e4xmplb5b22e0d - -To build a Lambda layer that contains the function's runtime dependencies, run `2-build-layer.sh`. Packaging dependencies in a layer reduces the size of the deployment package that you upload when you modify your code. - - java-events-v1sdk$ ./2-build-layer.sh - -# Deploy -Run `3-deploy.sh` to build the application with Gradle and deploy it. - - java-events-v1sdk$ ./3-deploy.sh - BUILD SUCCESSFUL in 1s - Successfully packaged artifacts and wrote output template to file out.yml. - Waiting for changeset to be created.. - Successfully created/updated stack - java-events-v1sdk - -This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code. - -You can also build the application with Maven. To use maven, add `mvn` to the command. - - java-events-v1sdk$ ./3-deploy.sh mvn - [INFO] Scanning for projects... - [INFO] -----------------------< com.example:java-events-v1sdk >----------------------- - [INFO] Building java-events-v1sdk-function 1.0-SNAPSHOT - [INFO] --------------------------------[ jar ]--------------------------------- - ... - -# Test -Run `4-invoke.sh` to invoke the function. - - java-events-v1sdk$ ./4-invoke.sh - { - "StatusCode": 200, - "ExecutedVersion": "$LATEST" - } - "200 OK" - -Let the script invoke the function a few times and then press `CRTL+C` to exit. - -The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. - -![Service Map](/sample-apps/java-events-v1sdk/images/java-events-v1sdk-servicemap.png) - -Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function. - -![Trace](/sample-apps/java-events-v1sdk/images/java-events-v1sdk-trace.png) - -# Configure Handler Class - -By default, the function uses a handler class named `Handler` that takes an Amazon S3 notification event as input and returns a string. The project also includes handlers that use other input and output types. The handlers are defined in the following files under `src/main/java/example`: - -- `Handler.java` - Takes `S3Event` as input. -- `HandlerDynamoDB.java` - Takes `DynamoDBEvent` as input. -- `HandlerKinesis.java` - Takes `KinesisEvent` as input. - -To use a different handler, change the value of the Handler setting in the application template (`template.yml` or `template-mvn.yaml`). For example, to use the Kinesis handler: - - Properties: - CodeUri: build/distributions/java-events-v1sdk.zip - Handler: example.HandlerKinesis - -Deploy the change, and then use the invoke script to test the new configuration. Pass the handler type key as an argument to the invoke script. - - ./4-invoke.sh kin - { - "StatusCode": 200, - "ExecutedVersion": "$LATEST" - } - "200 OK" - -The following event type keys are supported: -- none - S3 notification (`events/s3-notification.json`) -- `kin` - Kinesis record (`events/kinesis-record.json`) -- `ddb` - DynamoDB record (`events/dynamodb-record.json`) - -# Cleanup -To delete the application, run `5-cleanup.sh`. - - java-events-v1sdk$ ./5-cleanup.sh diff --git a/sample-apps/java-events-v1sdk/build.gradle b/sample-apps/java-events-v1sdk/build.gradle deleted file mode 100644 index abf8b34c..00000000 --- a/sample-apps/java-events-v1sdk/build.gradle +++ /dev/null @@ -1,56 +0,0 @@ -plugins { - id 'java' -} - -repositories { - mavenCentral() -} - -dependencies { - implementation platform('com.amazonaws:aws-xray-recorder-sdk-bom:2.4.0') - implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' - implementation 'com.amazonaws:aws-lambda-java-events:2.2.9' - implementation 'com.amazonaws:aws-java-sdk-s3:1.12.261' - implementation 'com.amazonaws:aws-java-sdk-kinesis:1.11.578' - implementation 'com.amazonaws:aws-java-sdk-dynamodb:1.11.578' - implementation 'com.amazonaws:aws-xray-recorder-sdk-core' - implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk' - implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-instrumentor' - implementation 'com.google.code.gson:gson:2.8.9' - implementation 'org.apache.logging.log4j:log4j-api:[2.17.1,)' - implementation 'org.apache.logging.log4j:log4j-core:[2.17.1,)' - implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:[2.17.1,)' - runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.5.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' -} - -test { - useJUnitPlatform() -} - -task packageBig(type: Zip) { - from compileJava - from processResources - into('lib') { - from configurations.runtimeClasspath - } -} - -task packageLibs(type: Zip) { - into('java/lib') { - from configurations.runtimeClasspath - } -} - -task packageSmall(type: Zip) { - from compileJava - from processResources -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -build.dependsOn packageSmall \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/event.json b/sample-apps/java-events-v1sdk/event.json deleted file mode 100644 index 94c28f5c..00000000 --- a/sample-apps/java-events-v1sdk/event.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "Records": [ - { - "awsRegion": "us-east-2", - "eventName": "ObjectCreated:Put", - "eventSource": "aws:s3", - "eventTime": "2020-03-08T00:30:12.456Z", - "eventVersion": "2.1", - "requestParameters": { - "sourceIPAddress": "174.255.255.156" - }, - "responseElements": { - "xAmzId2": "nBbLJPAHhdvxmplPvtCgTrWCqf/KtonyV93l9rcoMLeIWJxpS9x9P8u01+Tj0OdbAoGs+VGvEvWl/Sg1NW5uEsVO25Laq7L", - "xAmzRequestId": "AF2D7AB6002E898D" - }, - "s3": { - "configurationId": "682bbb7a-xmpl-48ca-94b1-7f77c4d6dbf0", - "bucket": { - "name": "BUCKET_NAME", - "ownerIdentity": { - "principalId": "A3XMPLFAF2AI3E" - }, - "arn": "arn:aws:s3:::BUCKET_NAME" - }, - "object": { - "key": "inbound/sample-java-s3.png", - "size": 21476, - "eTag": "d132690b6c65b6d1629721dcfb49b883", - "versionId": "", - "sequencer": "005E64A65DF093B26D" - }, - "s3SchemaVersion": "1.0" - }, - "userIdentity": { - "principalId": "AWS:AIDAINPONIXMPLT3IKHL2" - } - } - ] -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/events/dynamodb-record.json b/sample-apps/java-events-v1sdk/events/dynamodb-record.json deleted file mode 100644 index 74a055e8..00000000 --- a/sample-apps/java-events-v1sdk/events/dynamodb-record.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "Records": [ - { - "eventID": "1", - "eventVersion": "1.0", - "dynamodb": { - "Keys": { - "Id": { - "N": "101" - } - }, - "NewImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES", - "SequenceNumber": "111", - "SizeBytes": 26 - }, - "awsRegion": "us-west-2", - "eventName": "INSERT", - "eventSourceARN": "eventsourcearn", - "eventSource": "aws:dynamodb" - }, - { - "eventID": "2", - "eventVersion": "1.0", - "dynamodb": { - "OldImage": { - "Message": { - "S": "New item!" - }, - "Id": { - "N": "101" - } - }, - "SequenceNumber": "222", - "Keys": { - "Id": { - "N": "101" - } - }, - "SizeBytes": 59, - "NewImage": { - "Message": { - "S": "This item has changed" - }, - "Id": { - "N": "101" - } - }, - "StreamViewType": "NEW_AND_OLD_IMAGES" - }, - "awsRegion": "us-west-2", - "eventName": "MODIFY", - "eventSourceARN": "sourcearn", - "eventSource": "aws:dynamodb" - } - ] -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/events/kinesis-record.json b/sample-apps/java-events-v1sdk/events/kinesis-record.json deleted file mode 100644 index 8bc3e069..00000000 --- a/sample-apps/java-events-v1sdk/events/kinesis-record.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "Records": [ - { - "kinesis": { - "kinesisSchemaVersion": "1.0", - "partitionKey": "1", - "sequenceNumber": "49590338271490256608559692538361571095921575989136588898", - "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0Lg==", - "approximateArrivalTimestamp": 1545084650.987 - }, - "eventSource": "aws:kinesis", - "eventVersion": "1.0", - "eventID": "shardId-000000000006:49590338271490256608559692538361571095921575989136588898", - "eventName": "aws:kinesis:record", - "invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role", - "awsRegion": "us-east-2", - "eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream" - }, - { - "kinesis": { - "kinesisSchemaVersion": "1.0", - "partitionKey": "1", - "sequenceNumber": "49590338271490256608559692540925702759324208523137515618", - "data": "VGhpcyBpcyBvbmx5IGEgdGVzdC4=", - "approximateArrivalTimestamp": 1545084711.166 - }, - "eventSource": "aws:kinesis", - "eventVersion": "1.0", - "eventID": "shardId-000000000006:49590338271490256608559692540925702759324208523137515618", - "eventName": "aws:kinesis:record", - "invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role", - "awsRegion": "us-east-2", - "eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream" - } - ] -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/events/s3-notification.json b/sample-apps/java-events-v1sdk/events/s3-notification.json deleted file mode 100644 index 94c28f5c..00000000 --- a/sample-apps/java-events-v1sdk/events/s3-notification.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "Records": [ - { - "awsRegion": "us-east-2", - "eventName": "ObjectCreated:Put", - "eventSource": "aws:s3", - "eventTime": "2020-03-08T00:30:12.456Z", - "eventVersion": "2.1", - "requestParameters": { - "sourceIPAddress": "174.255.255.156" - }, - "responseElements": { - "xAmzId2": "nBbLJPAHhdvxmplPvtCgTrWCqf/KtonyV93l9rcoMLeIWJxpS9x9P8u01+Tj0OdbAoGs+VGvEvWl/Sg1NW5uEsVO25Laq7L", - "xAmzRequestId": "AF2D7AB6002E898D" - }, - "s3": { - "configurationId": "682bbb7a-xmpl-48ca-94b1-7f77c4d6dbf0", - "bucket": { - "name": "BUCKET_NAME", - "ownerIdentity": { - "principalId": "A3XMPLFAF2AI3E" - }, - "arn": "arn:aws:s3:::BUCKET_NAME" - }, - "object": { - "key": "inbound/sample-java-s3.png", - "size": 21476, - "eTag": "d132690b6c65b6d1629721dcfb49b883", - "versionId": "", - "sequencer": "005E64A65DF093B26D" - }, - "s3SchemaVersion": "1.0" - }, - "userIdentity": { - "principalId": "AWS:AIDAINPONIXMPLT3IKHL2" - } - } - ] -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/images/java-events-v1sdk-servicemap.png b/sample-apps/java-events-v1sdk/images/java-events-v1sdk-servicemap.png deleted file mode 100644 index 72afcfdb..00000000 Binary files a/sample-apps/java-events-v1sdk/images/java-events-v1sdk-servicemap.png and /dev/null differ diff --git a/sample-apps/java-events-v1sdk/images/java-events-v1sdk-trace.png b/sample-apps/java-events-v1sdk/images/java-events-v1sdk-trace.png deleted file mode 100644 index 4f921833..00000000 Binary files a/sample-apps/java-events-v1sdk/images/java-events-v1sdk-trace.png and /dev/null differ diff --git a/sample-apps/java-events-v1sdk/images/sample-java-events-v1sdk.png b/sample-apps/java-events-v1sdk/images/sample-java-events-v1sdk.png deleted file mode 100644 index 84349fbb..00000000 Binary files a/sample-apps/java-events-v1sdk/images/sample-java-events-v1sdk.png and /dev/null differ diff --git a/sample-apps/java-events-v1sdk/pom.xml b/sample-apps/java-events-v1sdk/pom.xml deleted file mode 100644 index 14683a39..00000000 --- a/sample-apps/java-events-v1sdk/pom.xml +++ /dev/null @@ -1,140 +0,0 @@ - - 4.0.0 - com.example - java-events-v1sdk - jar - 1.0-SNAPSHOT - java-events-v1sdk-function - - UTF-8 - 1.8 - 1.8 - - - - com.amazonaws - aws-lambda-java-core - 1.2.1 - - - com.amazonaws - aws-lambda-java-events - 2.2.9 - - - com.amazonaws - aws-lambda-java-log4j2 - 1.5.0 - - - com.google.code.gson - gson - 2.8.9 - - - org.apache.logging.log4j - log4j-api - [2.17.1,) - - - org.apache.logging.log4j - log4j-core - [2.17.1,) - - - org.apache.logging.log4j - log4j-slf4j18-impl - [2.17.1,) - - - com.amazonaws - aws-java-sdk-s3 - 1.12.261 - - - com.amazonaws - aws-java-sdk-kinesis - 1.11.578 - - - com.amazonaws - aws-java-sdk-dynamodb - 1.11.578 - - - com.amazonaws - aws-xray-recorder-sdk-aws-sdk-core - 2.4.0 - - - com.amazonaws - aws-xray-recorder-sdk-aws-sdk - 2.4.0 - - - com.amazonaws - aws-xray-recorder-sdk-aws-sdk-instrumentor - 2.4.0 - - - org.junit.jupiter - junit-jupiter-api - 5.6.0 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.6.0 - test - - - - - - - maven-surefire-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.2 - - false - - - - package - - shade - - - - - - - - - - - - com.github.edwgiz - maven-shade-plugin.log4j2-cachefile-transformer - [2.17.1,) - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - - \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/main/java/example/Handler.java b/sample-apps/java-events-v1sdk/src/main/java/example/Handler.java deleted file mode 100644 index 6ec8c54d..00000000 --- a/sample-apps/java-events-v1sdk/src/main/java/example/Handler.java +++ /dev/null @@ -1,34 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.RequestHandler; -import com.amazonaws.services.lambda.runtime.events.S3Event; - -import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// Handler value: example.Handler -public class Handler implements RequestHandler{ - private static final Logger logger = LoggerFactory.getLogger(Handler.class); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - @Override - public String handleRequest(S3Event event, Context context) - { - String response = new String("200 OK"); - S3EventNotificationRecord record = event.getRecords().get(0); - String srcBucket = record.getS3().getBucket().getName(); - // Object key may have spaces or unicode non-ASCII characters. - String srcKey = record.getS3().getObject().getUrlDecodedKey(); - logger.info("RECORD: " + record); - logger.info("SOURCE BUCKET: " + srcBucket); - logger.info("SOURCE KEY: " + srcKey); - // log execution details - Util.logEnvironment(event, context, gson); - return response; - } -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/main/java/example/HandlerDynamoDB.java b/sample-apps/java-events-v1sdk/src/main/java/example/HandlerDynamoDB.java deleted file mode 100644 index da0c0281..00000000 --- a/sample-apps/java-events-v1sdk/src/main/java/example/HandlerDynamoDB.java +++ /dev/null @@ -1,32 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.RequestHandler; -import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; -import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// Handler value: example.HandlerDynamoDB -public class HandlerDynamoDB implements RequestHandler{ - private static final Logger logger = LoggerFactory.getLogger(HandlerDynamoDB.class); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - @Override - public String handleRequest(DynamodbEvent event, Context context) - { - String response = new String("200 OK"); - for (DynamodbStreamRecord record : event.getRecords()){ - logger.info(record.getEventID()); - logger.info(record.getEventName()); - logger.info(record.getDynamodb().toString()); - } - logger.info("Successfully processed " + event.getRecords().size() + " records."); - // log execution details - Util.logEnvironment(event, context, gson); - return response; - } -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/main/java/example/HandlerKinesis.java b/sample-apps/java-events-v1sdk/src/main/java/example/HandlerKinesis.java deleted file mode 100644 index e46720df..00000000 --- a/sample-apps/java-events-v1sdk/src/main/java/example/HandlerKinesis.java +++ /dev/null @@ -1,29 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.RequestHandler; -import com.amazonaws.services.lambda.runtime.events.KinesisEvent; -import com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// Handler value: example.HandleKinesis -public class HandlerKinesis implements RequestHandler{ - private static final Logger logger = LoggerFactory.getLogger(HandlerKinesis.class); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - @Override - public String handleRequest(KinesisEvent event, Context context) - { - String response = new String("200 OK"); - for(KinesisEventRecord record : event.getRecords()) { - logger.info(gson.toJson(record.getKinesis().getData())); - } - // log execution details - Util.logEnvironment(event, context, gson); - return response; - } -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/main/java/example/Util.java b/sample-apps/java-events-v1sdk/src/main/java/example/Util.java deleted file mode 100644 index feb7475b..00000000 --- a/sample-apps/java-events-v1sdk/src/main/java/example/Util.java +++ /dev/null @@ -1,22 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; - -import com.google.gson.Gson; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Util { - private static final Logger logger = LoggerFactory.getLogger(Util.class); - - public static void logEnvironment(Object event, Context context, Gson gson) - { - // log execution details - logger.info("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv())); - logger.info("CONTEXT: " + gson.toJson(context)); - // log event details - logger.info("EVENT: " + gson.toJson(event)); - logger.info("EVENT TYPE: " + event.getClass().toString()); - } -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/main/resources/log4j2.xml b/sample-apps/java-events-v1sdk/src/main/resources/log4j2.xml deleted file mode 100644 index 6c830a00..00000000 --- a/sample-apps/java-events-v1sdk/src/main/resources/log4j2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - %d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1} - %m%n - - - - - - - - - - - \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/test/java/example/InvokeTest.java b/sample-apps/java-events-v1sdk/src/test/java/example/InvokeTest.java deleted file mode 100644 index 60ed4a8e..00000000 --- a/sample-apps/java-events-v1sdk/src/test/java/example/InvokeTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package example; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.events.S3Event; -import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord; -import com.amazonaws.services.s3.event.S3EventNotification.RequestParametersEntity; -import com.amazonaws.services.s3.event.S3EventNotification.ResponseElementsEntity; -import com.amazonaws.services.s3.event.S3EventNotification.S3Entity; -import com.amazonaws.services.s3.event.S3EventNotification.UserIdentityEntity; -import com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity; -import com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.lang.Long; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.io.IOException; - -import com.amazonaws.xray.AWSXRay; -import com.amazonaws.xray.AWSXRayRecorderBuilder; -import com.amazonaws.xray.strategy.sampling.NoSamplingStrategy; - -class InvokeTest { - - public InvokeTest() { - AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard(); - builder.withSamplingStrategy(new NoSamplingStrategy()); - AWSXRay.setGlobalRecorder(builder.build()); - } - - @Test - void invokeTest() throws IOException { - AWSXRay.beginSegment("java-s3-test"); - String bucket = new String(Files.readAllLines(Paths.get("bucket-name.txt")).get(0)); - S3EventNotificationRecord record = new S3EventNotificationRecord("us-east-2", - "ObjectCreated:Put", - "aws:s3", - "2020-03-08T00:30:12.456Z", - "2.1", - new RequestParametersEntity("174.255.255.156"), - new ResponseElementsEntity("nBbLJPAHhdvxmplPvtCgTrWCqf/KtonyV93l9rcoMLeIWJxpS9x9P8u01+Tj0OdbAoGs+VGvEvWl/Sg1NW5uEsVO25Laq7L", "AF2D7AB6002E898D"), - new S3Entity("682bbb7a-xmpl-48ca-94b1-7f77c4d6dbf0", - new S3BucketEntity(bucket, - new UserIdentityEntity("A3XMPLFAF2AI3E"), - "arn:aws:s3:::" + bucket), - new S3ObjectEntity("inbound/sample-java-s3.png", - new Long(21476), - "d132690b6c65b6d1629721dcfb49b883", - "", - "005E64A65DF093B26D"), - "1.0"), - new UserIdentityEntity("AWS:AIDAINPONIXMPLT3IKHL2")); - ArrayList records = new ArrayList(); - records.add(record); - S3Event event = new S3Event(records); - - Context context = new TestContext(); - Handler handler = new Handler(); - String result = handler.handleRequest(event, context); - assertTrue(result.contains("200 OK")); - AWSXRay.endSegment(); - } - -} diff --git a/sample-apps/java-events-v1sdk/src/test/java/example/TestContext.java b/sample-apps/java-events-v1sdk/src/test/java/example/TestContext.java deleted file mode 100644 index 69e0af00..00000000 --- a/sample-apps/java-events-v1sdk/src/test/java/example/TestContext.java +++ /dev/null @@ -1,45 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.CognitoIdentity; -import com.amazonaws.services.lambda.runtime.ClientContext; -import com.amazonaws.services.lambda.runtime.LambdaLogger; - -public class TestContext implements Context{ - - public TestContext() {} - public String getAwsRequestId(){ - return new String("495b12a8-xmpl-4eca-8168-160484189f99"); - } - public String getLogGroupName(){ - return new String("/aws/lambda/my-function"); - } - public String getLogStreamName(){ - return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a"); - } - public String getFunctionName(){ - return new String("my-function"); - } - public String getFunctionVersion(){ - return new String("$LATEST"); - } - public String getInvokedFunctionArn(){ - return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function"); - } - public CognitoIdentity getIdentity(){ - return null; - } - public ClientContext getClientContext(){ - return null; - } - public int getRemainingTimeInMillis(){ - return 300000; - } - public int getMemoryLimitInMB(){ - return 512; - } - public LambdaLogger getLogger(){ - return new TestLogger(); - } - -} \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/src/test/java/example/TestLogger.java b/sample-apps/java-events-v1sdk/src/test/java/example/TestLogger.java deleted file mode 100644 index 1d3c8efc..00000000 --- a/sample-apps/java-events-v1sdk/src/test/java/example/TestLogger.java +++ /dev/null @@ -1,14 +0,0 @@ -package example; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.amazonaws.services.lambda.runtime.LambdaLogger; - -public class TestLogger implements LambdaLogger { - private static final Logger logger = LoggerFactory.getLogger(TestLogger.class); - public void log(String message){ - logger.info(message); - } - public void log(byte[] message){ - logger.info(new String(message)); - } -} diff --git a/sample-apps/java-events-v1sdk/src/test/resources/log4j2.xml b/sample-apps/java-events-v1sdk/src/test/resources/log4j2.xml deleted file mode 100644 index 3b69545f..00000000 --- a/sample-apps/java-events-v1sdk/src/test/resources/log4j2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample-apps/java-events-v1sdk/template-mvn.yml b/sample-apps/java-events-v1sdk/template-mvn.yml deleted file mode 100644 index 6cabcd01..00000000 --- a/sample-apps/java-events-v1sdk/template-mvn.yml +++ /dev/null @@ -1,20 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: An AWS Lambda application that calls the Lambda API. -Resources: - function: - Type: AWS::Serverless::Function - Properties: - CodeUri: target/java-events-v1sdk-1.0-SNAPSHOT.jar - Handler: example.Handler - Runtime: java8 - Description: Java function - MemorySize: 512 - Timeout: 15 - # Function's execution role - Policies: - - AWSLambdaBasicExecutionRole - - AWSLambda_ReadOnlyAccess - - AWSXrayWriteOnlyAccess - - AWSLambdaVPCAccessExecutionRole - Tracing: Active diff --git a/sample-apps/java-events-v1sdk/template.yml b/sample-apps/java-events-v1sdk/template.yml deleted file mode 100644 index b1f59be5..00000000 --- a/sample-apps/java-events-v1sdk/template.yml +++ /dev/null @@ -1,30 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: An AWS Lambda application that calls the Lambda API. -Resources: - function: - Type: AWS::Serverless::Function - Properties: - CodeUri: build/distributions/java-events-v1sdk.zip - Handler: example.Handler - Runtime: java8 - Description: Java function - MemorySize: 512 - Timeout: 15 - # Function's execution role - Policies: - - AWSLambdaBasicExecutionRole - - AWSLambda_ReadOnlyAccess - - AWSXrayWriteOnlyAccess - - AWSLambdaVPCAccessExecutionRole - Tracing: Active - Layers: - - !Ref libs - libs: - Type: AWS::Serverless::LayerVersion - Properties: - LayerName: java-events-v1sdk-lib - Description: Dependencies for the Java S3 sample app. - ContentUri: build/java-events-v1sdk-lib.zip - CompatibleRuntimes: - - java8 diff --git a/sample-apps/java17-examples/1-create-bucket.sh b/sample-apps/java17-examples/1-create-bucket.sh deleted file mode 100755 index 64a5f749..00000000 --- a/sample-apps/java17-examples/1-create-bucket.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -BUCKET_ID=$(dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n') -BUCKET_NAME=lambda-artifacts-$BUCKET_ID -echo $BUCKET_NAME > bucket-name.txt -aws s3 mb s3://$BUCKET_NAME diff --git a/sample-apps/java17-examples/2-deploy.sh b/sample-apps/java17-examples/2-deploy.sh deleted file mode 100755 index 73723ab9..00000000 --- a/sample-apps/java17-examples/2-deploy.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -eo pipefail -ARTIFACT_BUCKET=$(cat bucket-name.txt) -TEMPLATE=template.yml -if [ $1 ] -then - if [ $1 = mvn ] - then - TEMPLATE=template-mvn.yml - mvn package - fi -else - gradle build -i -fi -aws cloudformation package --template-file $TEMPLATE --s3-bucket $ARTIFACT_BUCKET --output-template-file out.yml -aws cloudformation deploy --template-file out.yml --stack-name java17-examples --capabilities CAPABILITY_NAMED_IAM diff --git a/sample-apps/java17-examples/3-invoke.sh b/sample-apps/java17-examples/3-invoke.sh deleted file mode 100755 index 7ff3bf1b..00000000 --- a/sample-apps/java17-examples/3-invoke.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -set -eo pipefail -FUNCTION=$(aws cloudformation describe-stack-resource --stack-name java17-examples --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) -if [ $1 ] -then - case $1 in - string) - PAYLOAD='"MYSTRING"' - ;; - - int | integer) - PAYLOAD=12345 - ;; - - list) - PAYLOAD='[24,25,26]' - ;; - - divide) - PAYLOAD='[235241,17]' - ;; - - *) - echo -n "Unknown event type" - ;; - esac -fi -while true; do - if [ $PAYLOAD ] - then - aws lambda invoke --function-name $FUNCTION --payload $PAYLOAD out.json - else - aws lambda invoke --function-name $FUNCTION --payload fileb://event.json out.json - fi - cat out.json - echo "" - sleep 2 -done diff --git a/sample-apps/java17-examples/4-cleanup.sh b/sample-apps/java17-examples/4-cleanup.sh deleted file mode 100755 index 45bb0df8..00000000 --- a/sample-apps/java17-examples/4-cleanup.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -set -eo pipefail -STACK=java17-examples -if [[ $# -eq 1 ]] ; then - STACK=$1 - echo "Deleting stack $STACK" -fi -FUNCTION=$(aws cloudformation describe-stack-resource --stack-name $STACK --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text) -aws cloudformation delete-stack --stack-name $STACK -echo "Deleted $STACK stack." - -if [ -f bucket-name.txt ]; then - ARTIFACT_BUCKET=$(cat bucket-name.txt) - if [[ ! $ARTIFACT_BUCKET =~ lambda-artifacts-[a-z0-9]{16} ]] ; then - echo "Bucket was not created by this application. Skipping." - else - while true; do - read -p "Delete deployment artifacts and bucket ($ARTIFACT_BUCKET)? (y/n)" response - case $response in - [Yy]* ) aws s3 rb --force s3://$ARTIFACT_BUCKET; rm bucket-name.txt; break;; - [Nn]* ) break;; - * ) echo "Response must start with y or n.";; - esac - done - fi -fi - -while true; do - read -p "Delete function log group (/aws/lambda/$FUNCTION)? (y/n)" response - case $response in - [Yy]* ) aws logs delete-log-group --log-group-name /aws/lambda/$FUNCTION; break;; - [Nn]* ) break;; - * ) echo "Response must start with y or n.";; - esac -done - -rm -f out.yml out.json -rm -rf build .gradle target diff --git a/sample-apps/java17-examples/README.md b/sample-apps/java17-examples/README.md deleted file mode 100644 index 9d0ab1ad..00000000 --- a/sample-apps/java17-examples/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Basic function with minimal dependencies (Java) - -![Architecture](/sample-apps/java-basic/images/sample-java-basic.png) - -The project source includes function code and supporting resources: -- `src/main` - A Java function. -- `src/test` - A unit test and helper classes. -- `template.yml` - An AWS CloudFormation template that creates an application. -- `build.gradle` - A Gradle build file. -- `pom.xml` - A Maven build file. -- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application. - -Use the following instructions to deploy the sample application. - -# Requirements -- [Java 17 runtime environment (SE JRE)](https://www.oracle.com/java/technologies/javase-downloads.html) -- [Gradle 5](https://gradle.org/releases/) or [Maven 3](https://maven.apache.org/docs/history.html) -- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash. -- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer. - -# Setup -Download or clone this repository. - - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git - $ cd aws-lambda-developer-guide/sample-apps/java17-examples - -To create a new bucket for deployment artifacts, run `1-create-bucket.sh`. - - java17-examples$ ./1-create-bucket.sh - make_bucket: lambda-artifacts-a5e4xmplb5b22e0d - -# Deploy -To deploy the application, run `2-deploy.sh`. - - java17-examples$ ./2-deploy.sh - BUILD SUCCESSFUL in 1s - Successfully packaged artifacts and wrote output template to file out.yml. - Waiting for changeset to be created.. - Successfully created/updated stack - java17-examples - -This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code. - -You can also build the application with Maven. To use maven, add `mvn` to the command. - - java17-examples$ ./2-deploy.sh mvn - [INFO] Scanning for projects... - [INFO] -----------------------< com.example:java17-examples >----------------------- - [INFO] Building java17-examples-function 1.0-SNAPSHOT - [INFO] --------------------------------[ jar ]--------------------------------- - ... - -# Test -To invoke the function, run `3-invoke.sh`. - - java17-examples$ ./3-invoke.sh - { - "StatusCode": 200, - "ExecutedVersion": "$LATEST" - } - 21 - -Let the script invoke the function a few times and then press `CRTL+C` to exit. - -# Cleanup -To delete the application, run `4-cleanup.sh`. - - java17-examples$ ./4-cleanup.sh diff --git a/sample-apps/java17-examples/build.gradle b/sample-apps/java17-examples/build.gradle deleted file mode 100644 index 6f4b7f25..00000000 --- a/sample-apps/java17-examples/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id 'java' -} - -repositories { - mavenCentral() -} - -dependencies { - implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' - implementation 'org.slf4j:slf4j-nop:2.0.6' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' -} - -test { - useJUnitPlatform() -} - -task buildZip(type: Zip) { - from compileJava - from processResources - into('lib') { - from configurations.runtimeClasspath - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -build.dependsOn buildZip diff --git a/sample-apps/java17-examples/event.json b/sample-apps/java17-examples/event.json deleted file mode 100644 index 8d9c02d0..00000000 --- a/sample-apps/java17-examples/event.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "x": 1, - "y": 20, - "message": "Hello World!" -} diff --git a/sample-apps/java17-examples/src/main/java/example/HandlerIntegerJava17.java b/sample-apps/java17-examples/src/main/java/example/HandlerIntegerJava17.java deleted file mode 100644 index c64d4097..00000000 --- a/sample-apps/java17-examples/src/main/java/example/HandlerIntegerJava17.java +++ /dev/null @@ -1,24 +0,0 @@ -package example; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.LambdaLogger; -import com.amazonaws.services.lambda.runtime.RequestHandler; - -// Handler value: example.HandlerInteger -public class HandlerIntegerJava17 implements RequestHandler{ - - @Override - /* - * Takes in an InputRecord, which contains two integers and a String. - * Logs the String, then returns the sum of the two Integers. - */ - public Integer handleRequest(IntegerRecord event, Context context) - { - LambdaLogger logger = context.getLogger(); - logger.log("String found: " + event.message()); - return event.x() + event.y(); - } -} - -record IntegerRecord(int x, int y, String message) { -} diff --git a/sample-apps/java17-examples/template-mvn.yml b/sample-apps/java17-examples/template-mvn.yml deleted file mode 100644 index 392f1031..00000000 --- a/sample-apps/java17-examples/template-mvn.yml +++ /dev/null @@ -1,20 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: An AWS Lambda application that calls the Lambda API. -Resources: - function: - Type: AWS::Serverless::Function - Properties: - CodeUri: target/java17-examples-1.0-SNAPSHOT.jar - Handler: example.HandlerIntegerJava17 - Runtime: java17 - Description: Java function - MemorySize: 2048 - Timeout: 10 - # Function's execution role - Policies: - - AWSLambdaBasicExecutionRole - - AWSLambda_ReadOnlyAccess - - AWSXrayWriteOnlyAccess - - AWSLambdaVPCAccessExecutionRole - Tracing: Active diff --git a/sample-apps/java17-examples/template.yml b/sample-apps/java17-examples/template.yml deleted file mode 100644 index 42fc6085..00000000 --- a/sample-apps/java17-examples/template.yml +++ /dev/null @@ -1,20 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Transform: 'AWS::Serverless-2016-10-31' -Description: An AWS Lambda application that calls the Lambda API. -Resources: - function: - Type: AWS::Serverless::Function - Properties: - CodeUri: build/distributions/java17-examples.zip - Handler: example.HandlerIntegerJava17 - Runtime: java17 - Description: Java function - MemorySize: 2048 - Timeout: 10 - # Function's execution role - Policies: - - AWSLambdaBasicExecutionRole - - AWSLambda_ReadOnlyAccess - - AWSXrayWriteOnlyAccess - - AWSLambdaVPCAccessExecutionRole - Tracing: Active diff --git a/sample-apps/layer-nodejs/function-js/index.mjs b/sample-apps/layer-nodejs/function-js/index.mjs new file mode 100644 index 00000000..d94c925c --- /dev/null +++ b/sample-apps/layer-nodejs/function-js/index.mjs @@ -0,0 +1,17 @@ +import _ from "lodash" + +export const handler = async (event) => { + + var users = [ + { 'user': 'Carlos', 'active': true }, + { 'user': 'Gil-dong', 'active': false }, + { 'user': 'Pat', 'active': false } + ]; + + let out = _.findLastIndex(users, function(o) { return o.user == 'Pat'; }); + const response = { + statusCode: 200, + body: JSON.stringify(out + ", " + users[out].user), + }; + return response; +}; diff --git a/sample-apps/layer-nodejs/function-ts/index.ts b/sample-apps/layer-nodejs/function-ts/index.ts new file mode 100644 index 00000000..83ecea6e --- /dev/null +++ b/sample-apps/layer-nodejs/function-ts/index.ts @@ -0,0 +1,28 @@ +import { Handler } from 'aws-lambda'; +import * as _ from 'lodash'; + +type User = { + user: string; + active: boolean; +} + +type UserResult = { + statusCode: number; + body: string; +} + +const users: User[] = [ + { 'user': 'Carlos', 'active': true }, + { 'user': 'Gil-dong', 'active': false }, + { 'user': 'Pat', 'active': false } +]; + +export const handler: Handler = async (): Promise => { + + let out = _.findLastIndex(users, (user: User) => { return user.user == 'Pat'; }); + const response = { + statusCode: 200, + body: JSON.stringify(out + ", " + users[out].user), + }; + return response; +}; diff --git a/sample-apps/layer-nodejs/function-ts/package.json b/sample-apps/layer-nodejs/function-ts/package.json new file mode 100644 index 00000000..1857273d --- /dev/null +++ b/sample-apps/layer-nodejs/function-ts/package.json @@ -0,0 +1,20 @@ +{ + "name": "lambda-typescript-layer-example", + "version": "1.0.0", + "main": "dist/index.js", + "scripts": { + "prebuild": "rm -rf dist", + "build": "tsc index.ts --module nodenext --lib es2020 --outDir dist/", + "postbuild": "cd dist && zip -r index.zip index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT-0", + "description": "", + "devDependencies": { + "@types/aws-lambda": "^8.10.145", + "@types/lodash": "^4.17.9", + "lodash": "^4.17.21", + "typescript": "^5.6.2" + } +} diff --git a/sample-apps/layer-nodejs/layer/1-install.sh b/sample-apps/layer-nodejs/layer/1-install.sh new file mode 100755 index 00000000..9c3be6f5 --- /dev/null +++ b/sample-apps/layer-nodejs/layer/1-install.sh @@ -0,0 +1 @@ +npm install . diff --git a/sample-apps/layer-nodejs/layer/2-package.sh b/sample-apps/layer-nodejs/layer/2-package.sh new file mode 100755 index 00000000..e8a5defc --- /dev/null +++ b/sample-apps/layer-nodejs/layer/2-package.sh @@ -0,0 +1,3 @@ +mkdir -p nodejs/node20 +cp -r node_modules nodejs/node20/ +zip -r layer_content.zip nodejs diff --git a/sample-apps/layer-nodejs/layer/package.json b/sample-apps/layer-nodejs/layer/package.json new file mode 100644 index 00000000..d2229f35 --- /dev/null +++ b/sample-apps/layer-nodejs/layer/package.json @@ -0,0 +1,14 @@ +{ + "name": "layer", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT-0", + "description": "", + "dependencies": { + "lodash": "4.17.21" + } +} diff --git a/sample-apps/layer-python/function-numpy/response.json b/sample-apps/layer-python/function-numpy/response.json deleted file mode 100644 index a93c1cef..00000000 --- a/sample-apps/layer-python/function-numpy/response.json +++ /dev/null @@ -1 +0,0 @@ -{"errorMessage": "Unable to import module 'lambda_function': No module named 'numpy'", "errorType": "Runtime.ImportModuleError", "requestId": "31c0a568-b1e1-4e63-8f76-1ddc89eea07c", "stackTrace": []} \ No newline at end of file diff --git a/sample-apps/layer-python/function/response.json b/sample-apps/layer-python/function/response.json deleted file mode 100644 index 7a7e22f9..00000000 --- a/sample-apps/layer-python/function/response.json +++ /dev/null @@ -1 +0,0 @@ -{"statusCode": 200, "body": "{\"current_user_url\":\"https://api.github.com/user\",\"current_user_authorizations_html_url\":\"https://github.com/settings/connections/applications{/client_id}\",\"authorizations_url\":\"https://api.github.com/authorizations\",\"code_search_url\":\"https://api.github.com/search/code?q={query}{&page,per_page,sort,order}\",\"commit_search_url\":\"https://api.github.com/search/commits?q={query}{&page,per_page,sort,order}\",\"emails_url\":\"https://api.github.com/user/emails\",\"emojis_url\":\"https://api.github.com/emojis\",\"events_url\":\"https://api.github.com/events\",\"feeds_url\":\"https://api.github.com/feeds\",\"followers_url\":\"https://api.github.com/user/followers\",\"following_url\":\"https://api.github.com/user/following{/target}\",\"gists_url\":\"https://api.github.com/gists{/gist_id}\",\"hub_url\":\"https://api.github.com/hub\",\"issue_search_url\":\"https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}\",\"issues_url\":\"https://api.github.com/issues\",\"keys_url\":\"https://api.github.com/user/keys\",\"label_search_url\":\"https://api.github.com/search/labels?q={query}&repository_id={repository_id}{&page,per_page}\",\"notifications_url\":\"https://api.github.com/notifications\",\"organization_url\":\"https://api.github.com/orgs/{org}\",\"organization_repositories_url\":\"https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}\",\"organization_teams_url\":\"https://api.github.com/orgs/{org}/teams\",\"public_gists_url\":\"https://api.github.com/gists/public\",\"rate_limit_url\":\"https://api.github.com/rate_limit\",\"repository_url\":\"https://api.github.com/repos/{owner}/{repo}\",\"repository_search_url\":\"https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}\",\"current_user_repositories_url\":\"https://api.github.com/user/repos{?type,page,per_page,sort}\",\"starred_url\":\"https://api.github.com/user/starred{/owner}{/repo}\",\"starred_gists_url\":\"https://api.github.com/gists/starred\",\"topic_search_url\":\"https://api.github.com/search/topics?q={query}{&page,per_page}\",\"user_url\":\"https://api.github.com/users/{user}\",\"user_organizations_url\":\"https://api.github.com/user/orgs\",\"user_repositories_url\":\"https://api.github.com/users/{user}/repos{?type,page,per_page,sort}\",\"user_search_url\":\"https://api.github.com/search/users?q={query}{&page,per_page,sort,order}\"}"} \ No newline at end of file diff --git a/sample-apps/layer-python/layer/1-install.sh b/sample-apps/layer-python/layer/1-install.sh index 97f79f97..c9d93b81 100755 --- a/sample-apps/layer-python/layer/1-install.sh +++ b/sample-apps/layer-python/layer/1-install.sh @@ -1,3 +1,3 @@ -python3.11 -m venv create_layer +python3.13 -m venv create_layer source create_layer/bin/activate pip install -r requirements.txt diff --git a/sample-apps/layer-python/layer/create_layer/pyvenv.cfg b/sample-apps/layer-python/layer/create_layer/pyvenv.cfg deleted file mode 100644 index daa133da..00000000 --- a/sample-apps/layer-python/layer/create_layer/pyvenv.cfg +++ /dev/null @@ -1,5 +0,0 @@ -home = /opt/homebrew/opt/python@3.11/bin -include-system-site-packages = false -version = 3.11.6 -executable = /opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -command = /opt/homebrew/opt/python@3.11/bin/python3.11 -m venv /Users/yualexan/AWSDocProjects/aws-lambda-developer-guide/sample-apps/layer-python/layer/create_layer diff --git a/sample-apps/layer-ruby/function/lambda_function.rb b/sample-apps/layer-ruby/function/lambda_function.rb new file mode 100644 index 00000000..2c6d85d3 --- /dev/null +++ b/sample-apps/layer-ruby/function/lambda_function.rb @@ -0,0 +1,8 @@ +require 'json' +require 'tzinfo' + +def lambda_handler(event:, context:) + tz = TZInfo::Timezone.get('America/New_York') + { statusCode: 200, body: tz.to_local(Time.utc(2018, 2, 1, 12, 30, 0)) } +end + diff --git a/sample-apps/layer-ruby/layer/1-install.sh b/sample-apps/layer-ruby/layer/1-install.sh new file mode 100755 index 00000000..eaf29ac1 --- /dev/null +++ b/sample-apps/layer-ruby/layer/1-install.sh @@ -0,0 +1,3 @@ +bundle config set --local path 'vendor/bundle' +bundle install + diff --git a/sample-apps/layer-ruby/layer/2-package.sh b/sample-apps/layer-ruby/layer/2-package.sh new file mode 100755 index 00000000..305a5b7b --- /dev/null +++ b/sample-apps/layer-ruby/layer/2-package.sh @@ -0,0 +1,3 @@ +mkdir -p ruby/gems/3.3.0 +cp -r vendor/bundle/ruby/3.3.0/* ruby/gems/3.3.0/ +zip -r layer_content.zip ruby diff --git a/sample-apps/layer-ruby/layer/Gemfile b/sample-apps/layer-ruby/layer/Gemfile new file mode 100644 index 00000000..64ad6202 --- /dev/null +++ b/sample-apps/layer-ruby/layer/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "tzinfo"