Skip to content

Commit

Permalink
Merge branch 'aws-samples:main' into shankey28-feature-cdk-s3-sqs-lam…
Browse files Browse the repository at this point in the history
…bda-dynamodb
  • Loading branch information
shankey28 authored Aug 9, 2023
2 parents 546a63b + 7c5ee0c commit bfe6469
Show file tree
Hide file tree
Showing 718 changed files with 17,318 additions and 3,218 deletions.
4 changes: 2 additions & 2 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Push your code to the remote repos and [create a pull request](https://docs.gith

If this is the first push to the remote origin repo, you will be asked to Connect to GitHub to authorize the connection. Sometimes the pop-up window appears behind other windows.

1. Go to the [upstream repo](https://github.com/aws-samples/serverless-patterns) in Github and click "Compare & pull request".
1. Go to the [upstream repo](https://github.com/aws-samples/serverless-patterns) in GitHub and click "Compare & pull request".
1. Enter an appropriate title:

Example title: `New serverless pattern - lambda-aurora-serverless`
Expand Down Expand Up @@ -126,4 +126,4 @@ Delete any unnecessary local and origin branches.
1. API Gateway HTTP API to Lambda: [Website](https://serverlessland.com/patterns/apigw-lambda) | [GitHub](https://github.com/aws-samples/serverless-patterns/tree/main/apigw-http-api-lambda)
2. API Gateway REST API to DynamoDB: [Website](https://serverlessland.com/patterns/apigw-dynamodb) | [GitHub](https://github.com/aws-samples/serverless-patterns/tree/main/apigw-rest-api-dynamodb)
3. Lambda to SSM Parameter Store: [Website](https://serverlessland.com/patterns/lambda-ssm) | [GitHub](https://github.com/aws-samples/serverless-patterns/tree/main/lambda-ssm-parameter)
4. Lambda to S3 via a Custom Resource: [Website](https://serverlessland.com/patterns/lambda-s3-cfn) | [Github](https://github.com/aws-samples/serverless-patterns/tree/main/cfn-custom-resource-s3-create)
4. Lambda to S3 via a Custom Resource: [Website](https://serverlessland.com/patterns/lambda-s3-cfn) | [GitHub](https://github.com/aws-samples/serverless-patterns/tree/main/cfn-custom-resource-s3-create)
2 changes: 1 addition & 1 deletion _pattern-model/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-cognito-lambda/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-cdk/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-pulumi-cs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Important: this application uses various AWS services and there are costs associ
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
* [Pulumi](https://www.pulumi.com/docs/get-started/install/) installed
* [.NET Core](https://dotnet.microsoft.com/en-us/download) installed and configured
* [.NET 6](https://dotnet.microsoft.com/en-us/download) installed and configured

## Deployment Instructions

Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-pulumi-cs/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-pulumi-go/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
4 changes: 2 additions & 2 deletions alb-lambda-pulumi-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ require (
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
895 changes: 893 additions & 2 deletions alb-lambda-pulumi-go/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion alb-lambda-pulumi-js/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-pulumi-ts/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-pulumi-yaml/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
2 changes: 1 addition & 1 deletion alb-lambda-rust/example-pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"testing": {
"text": [
"See the Github repo for detailed testing instructions."
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
Expand Down
113 changes: 113 additions & 0 deletions alb-lambda-serverless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Application Load Balancer with Lambda as a target

This pattern registers the lambda function as the target for the Application Load Balancer.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

## Requirements

* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git CLI](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed
* [NodeJS](https://nodejs.org/en/download/) (LTS version) installed
* [Serverless Framework CLI](https://www.serverless.com/framework/docs/getting-started) installed

## Deployment Instructions

1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

``` sh
git clone https://github.com/aws-samples/serverless-patterns
```

1. Change directory to the pattern directory:

``` sh
cd serverless-patterns/alb-lambda-serverless
```

1. From the command line, use npm/yarn to install the development dependencies:

``` sh
npm install
```
-or-

``` sh
yarn install
```

1. From the command line, use Serverless Framework to deploy the AWS resources for the pattern as specified in the serverless.yml file:

``` sh
serverless deploy --verbose
```

The above command will deploy resources to `ap-south-1` region by default. You can override the target region with `--region <region>` CLI option, e.g.

``` sh
serverless deploy --verbose --region us-west-2
```

1. Note the `LoadBalancerDNSName` output from the Serverless Framework deployment process. You will use this value for testing.

## How it works

This pattern registers the lambda function as the target for the Application Load Balancer. When the load balancer endpoint is hit in the browser, if the specified URL (`/hello`) path matches, it triggers the lambda function & the file (hello) is downloaded in your local system with the output from lambda function.


## Testing

### Hit the Load Balancer DNS endpoint.

To test the endpoint, paste the output URL obtained from serverless framework in the browser of your choice.

### Expected result

As no specific URL path is provided, it returns the default output i.e. 404-Page Not Found.
```html
Page Not Found
```

Now edit the URL by appending the `/hello` path in it. This will download a file named `hello` in your local system. The file will have the following content.

```json
<p>Lambda function integrated with ALB called</p>
```

### CloudWatch logs

Open AWS CloudWatch Console and navigate to [/aws/lambda/alb-lambda-serverless-prod-functionOne](https://ap-south-1.console.aws.amazon.com/cloudwatch/home?region=ap-south-1#logsV2:log-groups/log-group/$252Faws$252Flambda$252Falb-lambda-serverless-prod-functionOne/) log group.
You should be able to see a new Event Stream with the Received Event information, and Event Message, logged into the stream.




## Cleanup

1. Delete the stack

```sh
serverless remove --verbose
```

1. Confirm the stack has been deleted

```sh
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'alb-lambda-serverless-prod')].StackStatus"
```

Expected output

```json
[
"DELETE_COMPLETE"
]
```

NOTE: You might need to add `--region <region>` option to AWS CLI command if you AWS CLI default region does not match the one, that you used for the Serverless Framework deployment.

----
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
66 changes: 66 additions & 0 deletions alb-lambda-serverless/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"title": "Application Load Balancer with Lambda as a target",
"description": "Create an Application Load Balancer with Lambda as target using Serverless Framework",
"language": "Node.js",
"architectureURL": "",
"videoId": "",
"level": "100",
"framework": "Serverless Framework",
"services": {
"from": "alb",
"to": "lambda"
},
"introBox": {
"headline": "How it works",
"text": [
"This pattern registers the lambda function as the target for the Application Load Balancer using the serverless framework.",
"",
"When the load balancer endpoint is hit in the browser, if the specified URL (`/hello`) path matches, it triggers the lambda function & the file (hello) is downloaded in your local system with the output from lambda function."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/alb-lambda-serverless",
"templateURL": "serverless-patterns/alb-lambda-serverless",
"projectFolder": "alb-lambda-serverless",
"templateFile": "serverless.yml"
}
},
"resources": {
"headline": "Additional resources",
"bullets": [
{
"text": "Using AWS Lambda with an Application Load Balancer",
"link": "https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html"
},
{
"text": "Lambda functions as targets - Elastic Load Balancing",
"link": "https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html"
}
]
},
"deploy": {
"text": [
"<code>serverless deploy --verbose</code>"
]
},
"testing": {
"text": [
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"<code>serverless remove --verbose</code>."
]
},
"authors": [
{
"headline": "Presented by Anjali Modi, Software Engineer, Distinction-Dev",
"name": "Anjali Modi",
"bio": "Anjali Modi is a Software Engineer working for developing Serverless solutions at Distinction-Dev, India",
"linkedin":"https://www.linkedin.com/in/anjali-modi-068045119/",
"imageURL": "https://1.gravatar.com/avatar/51f84b006e95184c3943b4d5e17b1ac3"
}
]
}
11 changes: 11 additions & 0 deletions alb-lambda-serverless/handlers/alb-lambda-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.handler=async(event, context) =>{
const response = {
statusCode: 200,
headers:{
contentType:'text/html'
},
body:'<p>Lambda function integrated with ALB called</p>'
}
console.log('response obj---', response)
return response
}
9 changes: 9 additions & 0 deletions alb-lambda-serverless/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "alb-lambda-serverless",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"serverless": "^3.33.0"
}
}
Loading

0 comments on commit bfe6469

Please sign in to comment.