From a2cab45d6611837862aad5c253baaa0906c2575b Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Tue, 23 Jul 2024 14:33:21 +0530 Subject: [PATCH 1/8] adding repo for websocket vpc link --- apigw-websocket-api-vpclink/README.md | 88 +++++++++++++++ .../example-pattern.json | 44 ++++++++ apigw-websocket-api-vpclink/template.yml | 101 ++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 apigw-websocket-api-vpclink/README.md create mode 100644 apigw-websocket-api-vpclink/example-pattern.json create mode 100644 apigw-websocket-api-vpclink/template.yml diff --git a/apigw-websocket-api-vpclink/README.md b/apigw-websocket-api-vpclink/README.md new file mode 100644 index 000000000..6ab3d1398 --- /dev/null +++ b/apigw-websocket-api-vpclink/README.md @@ -0,0 +1,88 @@ +Amazon API Gateway Websocket API with VPC Link integration + +The SAM template deploys an Amazon API Gateway Websocket API endpoint with a VPC Link integration. + +Since Websocket APIs only support VPC Links associated with NLBs (Network Load Balancers), this pattern assumes that an internal NLB already exists in a VPC in the same Region. + +Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-rest-api-vpclink + +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 for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. + + +Requirements + +* Create an AWS account 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 installed and configured +* Git Installed +* AWS Serverless Application Model (AWS SAM) installed + + + +Deployment Instructions + +* Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: + + +git clone https://github.com/aws-samples/serverless-patterns + + +Change directory to the pattern directory: + + +cd apigw-websocket-api-vpclink + + +From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: + + +sam deploy -g + + + +1. During the prompts: + + * Enter a stack name + * Select the desired AWS Region + * Enter the DNS name for the internal NLB (NlbInternalDns) + * Enter the ARN for the internal NLB (NlbInternalArn) + * Allow SAM to create roles with the required permissions if needed. + +Once you have run guided mode once, you can use sam deploy in future to use these defaults. + +1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing. + + + +Testing + +Once the application is deployed, retrieve the WebSocketURL value from CloudFormation Outputs. To test the WebSocket API, you can use wscat which is an open-source command line tool. + +1. Install NPM. +2. Install wscat: + + +$ npm install -g wscat + + +Connect to your WebSocketURL by executing the following command: + + +$ wscat -c + + + +Cleanup + +* Delete the stack + + +sam delete + + +Confirm the stack has been deleted + + +aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus" + + + diff --git a/apigw-websocket-api-vpclink/example-pattern.json b/apigw-websocket-api-vpclink/example-pattern.json new file mode 100644 index 000000000..b2d68d523 --- /dev/null +++ b/apigw-websocket-api-vpclink/example-pattern.json @@ -0,0 +1,44 @@ +{ + "title": "Amazon API Gateway Websocket API with VPC Link integration", + "description": "The SAM template deploys an Amazon API Gateway Websocket API endpoint with a VPC Link integration.", + "language": "Python", + "level": "200", + "framework": "SAM", + "gitHub": { + "template": { + "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-websocket-api-vpclink", + "templateURL": "serverless-patterns/apigw-websocket-api-vpclink", + "projectFolder": "apigw-websocket-api-vpclink", + "templateFile": "template.yaml" + } + }, + "deploy": { + "text": [ + "sam deploy" + ] + }, + "testing": { + "text": [ + "See the GitHub repo for detailed testing instructions." + ] + }, + "cleanup": { + "text": [ + "Delete the stack: sam delete." + ] + }, + "authors": [ + { + "name": "Manasvi Jain", + "image": "https://avatars.githubusercontent.com/u/56217984?v=4", + "bio": "Cloud Engineer at AWS", + "linkedin": "https://www.linkedin.com/in/manasvi-jain-36b9941a3/" + }, + { + "name": "Umang Aggarwal", + "image": "https://avatars.githubusercontent.com/Umang071", + "bio": "Cloud Engineer II @ AWS", + "linkedin": "https://www.linkedin.com/in/umangaggarwal" + } + ] +} diff --git a/apigw-websocket-api-vpclink/template.yml b/apigw-websocket-api-vpclink/template.yml new file mode 100644 index 000000000..8758af5d6 --- /dev/null +++ b/apigw-websocket-api-vpclink/template.yml @@ -0,0 +1,101 @@ +AWSTemplateFormatVersion: 2010-09-09 +Transform: AWS::Serverless-2016-10-31 +Description: An Amazon API Gateway WebSocket API and an AWS Lambda function. + +Parameters: + NlbInternalDns: + Type: String + NlbInternalArn: + Type: String + +Resources: + # API Gateway WebSocket API + MyWebSocketApi: + Type: AWS::ApiGatewayV2::Api + Properties: + Name: !Ref AWS::StackName + Description: An Amazon API Gateway WebSocket API and an AWS Lambda function. + ProtocolType: WEBSOCKET + RouteSelectionExpression: $request.body.action + + ConnectRoute: + Type: AWS::ApiGatewayV2::Route + Properties: + ApiId: !Ref MyWebSocketApi + RouteKey: $connect + Target: !Sub integrations/${ConnectIntegration} + + MessageRoute: + Type: AWS::ApiGatewayV2::Route + Properties: + ApiId: !Ref MyWebSocketApi + RouteKey: $default + Target: !Sub integrations/${MessageIntegration} + + DisconnectRoute: + Type: AWS::ApiGatewayV2::Route + Properties: + ApiId: !Ref MyWebSocketApi + RouteKey: $disconnect + Target: !Sub integrations/${DisconnectIntegration} + + ConnectIntegration: + Type: AWS::ApiGatewayV2::Integration + Properties: + ApiId: !Ref MyWebSocketApi + IntegrationType: HTTP_PROXY + IntegrationMethod: ANY + IntegrationUri: !Sub http://${NlbInternalDns}/connect + ConnectionType: VPC_LINK + ConnectionId: !Ref VPCLinkRestNlbInternal + + MessageIntegration: + Type: AWS::ApiGatewayV2::Integration + Properties: + ApiId: !Ref MyWebSocketApi + IntegrationType: HTTP_PROXY + IntegrationMethod: ANY + IntegrationUri: !Sub http://${NlbInternalDns}/message + ConnectionType: VPC_LINK + ConnectionId: !Ref VPCLinkRestNlbInternal + + DisconnectIntegration: + Type: AWS::ApiGatewayV2::Integration + Properties: + ApiId: !Ref MyWebSocketApi + IntegrationType: HTTP_PROXY + IntegrationMethod: ANY + IntegrationUri: !Sub http://${NlbInternalDns}/disconnect + ConnectionType: VPC_LINK + ConnectionId: !Ref VPCLinkRestNlbInternal + + Deployment: + Type: AWS::ApiGatewayV2::Deployment + DependsOn: + - ConnectRoute + - DisconnectRoute + - MessageRoute + Properties: + ApiId: !Ref MyWebSocketApi + + Stage: + Type: AWS::ApiGatewayV2::Stage + Properties: + StageName: Prod + ApiId: !Ref MyWebSocketApi + DeploymentId: !Ref Deployment + + VPCLinkRestNlbInternal: + Type: AWS::ApiGateway::VpcLink + Properties: + Name: VPCLinkRestNlbInternal + TargetArns: + - !Ref NlbInternalArn + +Outputs: + + # API Gateway endpoint to be used during tests + AppApiEndpoint: + Description: API Endpoint + Value: !Sub https://${MyWebSocketApi}.execute-api.${AWS::Region}.amazonaws.com/Prod + From 40f9e7be9ae73a46ac883ed3c1842dc62c6b3e90 Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Tue, 23 Jul 2024 23:20:31 +0530 Subject: [PATCH 2/8] apigw-websocket-api-vpclink --- apigw-websocket-api-vpclink/README.md | 114 ++++++++++++-------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/apigw-websocket-api-vpclink/README.md b/apigw-websocket-api-vpclink/README.md index 6ab3d1398..98087b152 100644 --- a/apigw-websocket-api-vpclink/README.md +++ b/apigw-websocket-api-vpclink/README.md @@ -1,4 +1,4 @@ -Amazon API Gateway Websocket API with VPC Link integration +# Amazon API Gateway Websocket API with VPC Link integration The SAM template deploys an Amazon API Gateway Websocket API endpoint with a VPC Link integration. @@ -8,81 +8,71 @@ Learn more about this pattern at Serverless Land Patterns: https://serverlesslan 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 for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. - -Requirements - -* Create an AWS account 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 installed and configured -* Git Installed -* AWS Serverless Application Model (AWS SAM) installed - - - -Deployment Instructions - -* Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: - - -git clone https://github.com/aws-samples/serverless-patterns - - -Change directory to the pattern directory: - - -cd apigw-websocket-api-vpclink - - -From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: - - -sam deploy -g - - - -1. During the prompts: - +## 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 Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed + +## Deployment Instructions + +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: + ``` + git clone https://github.com/aws-samples/serverless-patterns + ``` +2. Change directory to the pattern directory: + ``` + cd apigw-rest-api-vpclink + ``` +3. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: + ``` + sam deploy -g + ``` +4. During the prompts: * Enter a stack name * Select the desired AWS Region * Enter the DNS name for the internal NLB (NlbInternalDns) * Enter the ARN for the internal NLB (NlbInternalArn) * Allow SAM to create roles with the required permissions if needed. -Once you have run guided mode once, you can use sam deploy in future to use these defaults. + Once you have run guided mode once, you can use `sam deploy` in future to use these defaults. 1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing. +## Testing +Once the application is deployed, retrieve the WebSocketURL value from CloudFormation Outputs. To test the WebSocket API, you can use [wscat](https://github.com/websockets/wscat) which is an open-source command line tool. -Testing - -Once the application is deployed, retrieve the WebSocketURL value from CloudFormation Outputs. To test the WebSocket API, you can use wscat which is an open-source command line tool. +1. [Install NPM](https://www.npmjs.com/get-npm). -1. Install NPM. 2. Install wscat: - - -$ npm install -g wscat - - -Connect to your WebSocketURL by executing the following command: + ``` + $ npm install -g wscat + ``` +3. Connect to your WebSocketURL by executing the following command: + ``` + $ wscat -c + ``` +4. To test the custom route and its associated function, send a JSON-formatted request like the following example. The Lambda function sends back the value of the "data" key using the callback URL: +``` $ wscat -c - - - -Cleanup - -* Delete the stack - - -sam delete - - -Confirm the stack has been deleted - - -aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus" - - +connected (press CTRL+C to quit) +> {"action":"post", "data":"hello world"} +< hello world +``` + +## Cleanup + +1. Delete the stack + ``` + aws cloudformation delete-stack --stack-name + ``` + +2. Confirm the stack has been deleted + ``` + aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'')].StackStatus" + ``` From ba4e67e15999d7e5494e98a45b0e0cc732a3da86 Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 10:58:59 +0530 Subject: [PATCH 3/8] ack-connect-route --- ack-connect-route/README.md | 75 +++++++++ ack-connect-route/src/lambda_function.py | 15 ++ .../src/lambda_function_postToConnection.py | 14 ++ ack-connect-route/src/ondisconnect.py | 10 ++ ack-connect-route/template.yml | 142 ++++++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 ack-connect-route/README.md create mode 100644 ack-connect-route/src/lambda_function.py create mode 100644 ack-connect-route/src/lambda_function_postToConnection.py create mode 100644 ack-connect-route/src/ondisconnect.py create mode 100644 ack-connect-route/template.yml diff --git a/ack-connect-route/README.md b/ack-connect-route/README.md new file mode 100644 index 000000000..9b6340462 --- /dev/null +++ b/ack-connect-route/README.md @@ -0,0 +1,75 @@ +# Amazon API Gateway Websocket API with VPC Link integration + +The SAM template deploys an Amazon API Gateway Websocket API endpoint with a VPC Link integration. + +Since Websocket APIs only support VPC Links associated with NLBs (Network Load Balancers), this pattern assumes that an internal NLB already exists in a VPC in the same Region. + +Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-rest-api-vpclink + +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 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 Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed + +## Deployment Instructions + +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: + ``` + git clone https://github.com/aws-samples/serverless-patterns + ``` +2. Change directory to the pattern directory: + ``` + cd ack-connect-route + ``` +3. From the command line, use AWS SAM to build and deploy the AWS resources for the pattern as specified in the template.yml file: + + ``` + sam build + sam deploy --guided + ``` +4. During the prompts: + * Enter a stack name + * Enter the desired AWS Region + * Allow SAM CLI to create IAM roles with the required permissions. + + Once you have run guided mode once, you can use `sam deploy` in future to use these defaults. + +1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing. + +## Testing + +Once the application is deployed, retrieve the WebSocketURL value from CloudFormation Outputs. To test the WebSocket API, you can use [wscat](https://github.com/websockets/wscat) which is an open-source command line tool. + +1. [Install NPM](https://www.npmjs.com/get-npm). + +2. Install wscat: + ``` + $ npm install -g wscat + ``` + +3. Connect to your WebSocketURL by executing the following command: + ``` + $ wscat -c + ``` + +4. To test the custom route and its associated function, send a JSON-formatted request like the following example. The Lambda function sends back the value of the "data" key using the callback URL: +``` +$ wscat -c +connected (press CTRL+C to quit) + +## Cleanup + +1. Delete the stack + ``` + aws cloudformation delete-stack --stack-name + ``` + +2. Confirm the stack has been deleted + ``` + aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'')].StackStatus" + ``` + diff --git a/ack-connect-route/src/lambda_function.py b/ack-connect-route/src/lambda_function.py new file mode 100644 index 000000000..fe2296d51 --- /dev/null +++ b/ack-connect-route/src/lambda_function.py @@ -0,0 +1,15 @@ +import json +import boto3 + +lambdaClient = boto3.client('lambda') +def lambda_handler(event, context): + print("Got an event from some route ", event) + if event['requestContext']['routeKey'] == "$connect": + url = "https://" + event["requestContext"]["domainName"] + "/" + event["requestContext"]["stage"] + + response = lambdaClient.invoke(FunctionName="WebsocketPostToConnectionId",InvocationType="Event",Payload=json.dumps({"url": url, "connectionId":event['requestContext']['connectionId']})) + payload = "This won't be received by the client" + return {'statusCode': 200,'body': payload} + + + diff --git a/ack-connect-route/src/lambda_function_postToConnection.py b/ack-connect-route/src/lambda_function_postToConnection.py new file mode 100644 index 000000000..0c9efe6bb --- /dev/null +++ b/ack-connect-route/src/lambda_function_postToConnection.py @@ -0,0 +1,14 @@ +import json +import boto3 + +def lambda_handler(event, context): + + print("Got an event from parent lambda ", event) + gatewayapi = boto3.client("apigatewaymanagementapi",endpoint_url = event["url"]) + response = gatewayapi.get_connection(ConnectionId=event['connectionId']) + print("Response is ", response) + + if response["ResponseMetadata"]["HTTPStatusCode"] == 200: + gatewayapi.post_to_connection(ConnectionId=event['connectionId'], Data="Hello XXX, we are now connected!! ") + return {} + diff --git a/ack-connect-route/src/ondisconnect.py b/ack-connect-route/src/ondisconnect.py new file mode 100644 index 000000000..a20180f23 --- /dev/null +++ b/ack-connect-route/src/ondisconnect.py @@ -0,0 +1,10 @@ +import json + +def lambda_handler(event, context): + # TODO implement + print("Connection has been disconnected") + return { + 'statusCode': 200, + 'body': json.dumps('Hello from Lambda!') + } + diff --git a/ack-connect-route/template.yml b/ack-connect-route/template.yml new file mode 100644 index 000000000..2099161d0 --- /dev/null +++ b/ack-connect-route/template.yml @@ -0,0 +1,142 @@ +AWSTemplateFormatVersion: 2010-09-09 +Transform: 'AWS::Serverless-2016-10-31' +Description: An Amazon API Gateway WebSocket API and an AWS Lambda function. + +# Global values that are applied to all applicable resources in this template +Globals: + Function: + CodeUri: ./src + Runtime: python3.12 + MemorySize: 128 + Timeout: 15 + +Resources: + # API Gateway WebSocket API + WebSocketApi: + Type: 'AWS::ApiGatewayV2::Api' + Properties: + Name: !Ref AWS::StackName + Description: An Amazon API Gateway WebSocket API and an AWS Lambda function. + ProtocolType: WEBSOCKET + RouteSelectionExpression: "$request.body.action" + # Lambda Function - uses Globals to define additional configuration values + OnConnectLambdaFunction: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: !Sub '${AWS::StackName}-onconnect-function' + Handler: lambda_function.lambda_handler + MemorySize: 256 + Policies: + - Statement: + - Effect: Allow + Action: + - 'lambda:InvokeFunction' + Resource: + - !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:WebsocketPostToConnectionId' + # Function permissions grant an AWS service or another account permission to use a function + OnConnectFunctionResourcePermission: + Type: 'AWS::Lambda::Permission' + Properties: + Action: 'lambda:InvokeFunction' + Principal: apigateway.amazonaws.com + FunctionName: !Ref OnConnectLambdaFunction + SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebSocketApi}/*' + OnConnectIntegration: + Type: AWS::ApiGatewayV2::Integration + Properties: + ApiId: !Ref WebSocketApi + Description: OnConnect Integration + IntegrationType: AWS_PROXY + IntegrationUri: + Fn::Sub: + arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OnConnectLambdaFunction.Arn}/invocations + OnConnectRoute: + Type: AWS::ApiGatewayV2::Route + Properties: + ApiId: !Ref WebSocketApi + RouteKey: $connect + AuthorizationType: NONE + OperationName: OnConnectRoute + Target: !Join + - '/' + - - 'integrations' + - !Ref OnConnectIntegration + # Lambda Function - uses Globals to define additional configuration values + PostLambdaFunction: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: WebsocketPostToConnectionId + Handler: lambda_function_postToConnection.lambda_handler + MemorySize: 256 + Policies: + - Statement: + - Effect: Allow + Action: + - 'execute-api:ManageConnections' + Resource: + - !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebSocketApi}/*' + # Function permissions grant an AWS service or another account permission to use a function + + OnDisconnectLambdaFunction: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: !Sub '${AWS::StackName}-ondisconnect-function' + Handler: ondisconnect.lambda_handler + MemorySize: 256 + # Function permissions grant an AWS service or another account permission to use a function + OnDisconnectFunctionResourcePermission: + Type: 'AWS::Lambda::Permission' + Properties: + Action: 'lambda:InvokeFunction' + Principal: apigateway.amazonaws.com + FunctionName: !Ref OnDisconnectLambdaFunction + SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebSocketApi}/*' + OnDisconnectIntegration: + Type: AWS::ApiGatewayV2::Integration + Properties: + ApiId: !Ref WebSocketApi + Description: OnDisconnect Integration + IntegrationType: AWS_PROXY + IntegrationUri: + Fn::Sub: + arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OnDisconnectLambdaFunction.Arn}/invocations + OnDisconnectRoute: + Type: AWS::ApiGatewayV2::Route + Properties: + ApiId: !Ref WebSocketApi + RouteKey: $disconnect + AuthorizationType: NONE + OperationName: OnDisconnectRoute + Target: !Join + - '/' + - - 'integrations' + - !Ref OnDisconnectIntegration + Deployment: + Type: AWS::ApiGatewayV2::Deployment + DependsOn: + - OnConnectRoute + - OnDisconnectRoute + Properties: + ApiId: !Ref WebSocketApi + Stage: + Type: AWS::ApiGatewayV2::Stage + Properties: + StageName: prod + Description: Prod Stage + DeploymentId: !Ref Deployment + ApiId: !Ref WebSocketApi + +Outputs: + OnConnectLambdaFunctionArn: + Description: "OnConnect function ARN" + Value: !GetAtt OnConnectLambdaFunction.Arn + OnDisconnectLambdaFunctionArn: + Description: "OnDisconnect function ARN" + Value: !GetAtt OnDisconnectLambdaFunction.Arn + PostLambdaFunctionArn: + Description: "Post function ARN" + Value: !GetAtt PostLambdaFunction.Arn + WebSocketURL: + Description: "The WSS Protocol URL to connect to" + Value: !Join [ '', [ 'wss://', !Ref WebSocketApi, '.execute-api.',!Ref 'AWS::Region','.amazonaws.com/',!Ref 'Stage'] ] + From 70f5d4d09f101e03c8218822504425fe10d01e60 Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 11:05:20 +0530 Subject: [PATCH 4/8] ack-connect-route-final --- ack-connect-route/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ack-connect-route/README.md b/ack-connect-route/README.md index 9b6340462..9cc70464d 100644 --- a/ack-connect-route/README.md +++ b/ack-connect-route/README.md @@ -1,13 +1,12 @@ -# Amazon API Gateway Websocket API with VPC Link integration +#Websocket API Gateway acknowledgement for $connect route. -The SAM template deploys an Amazon API Gateway Websocket API endpoint with a VPC Link integration. +The SAM template deploys a websocket API Gateway and two Lambda functions required to run the application. This pattern deploys an Amazon API Gateway WebSocket API with a $connect route with a Lambda proxy integration which will invoke another Lambda function asynchronously and pass the Connection Id and the API Gateway stage URL to it. Then the Lambda function which got invoked asynchronously will check the validity of the connection. If the Connection Id is valid it will make an SDK API call to post a greeting to the client. -Since Websocket APIs only support VPC Links associated with NLBs (Network Load Balancers), this pattern assumes that an internal NLB already exists in a VPC in the same Region. - -Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-rest-api-vpclink +Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/s3-lambda 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 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. @@ -73,3 +72,4 @@ connected (press CTRL+C to quit) aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'')].StackStatus" ``` + From d9e37593d801c00a05dc2d3cde2f461afa9a53e0 Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 11:06:44 +0530 Subject: [PATCH 5/8] ack-connect-route-final --- ack-connect-route/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ack-connect-route/README.md b/ack-connect-route/README.md index 9cc70464d..b0fcd44d0 100644 --- a/ack-connect-route/README.md +++ b/ack-connect-route/README.md @@ -1,4 +1,4 @@ -#Websocket API Gateway acknowledgement for $connect route. +##Websocket API Gateway acknowledgement for $connect route. The SAM template deploys a websocket API Gateway and two Lambda functions required to run the application. This pattern deploys an Amazon API Gateway WebSocket API with a $connect route with a Lambda proxy integration which will invoke another Lambda function asynchronously and pass the Connection Id and the API Gateway stage URL to it. Then the Lambda function which got invoked asynchronously will check the validity of the connection. If the Connection Id is valid it will make an SDK API call to post a greeting to the client. From 458586ac157eb9a618030406e9732c2a3cff6e4d Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 11:07:33 +0530 Subject: [PATCH 6/8] ack-connect-route-final --- ack-connect-route/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ack-connect-route/README.md b/ack-connect-route/README.md index b0fcd44d0..0988398e5 100644 --- a/ack-connect-route/README.md +++ b/ack-connect-route/README.md @@ -1,4 +1,4 @@ -##Websocket API Gateway acknowledgement for $connect route. +## Websocket API Gateway acknowledgement for $connect route. The SAM template deploys a websocket API Gateway and two Lambda functions required to run the application. This pattern deploys an Amazon API Gateway WebSocket API with a $connect route with a Lambda proxy integration which will invoke another Lambda function asynchronously and pass the Connection Id and the API Gateway stage URL to it. Then the Lambda function which got invoked asynchronously will check the validity of the connection. If the Connection Id is valid it will make an SDK API call to post a greeting to the client. From 43b433eec9c79d28fb5401657cfb15e335ecc33e Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 11:18:05 +0530 Subject: [PATCH 7/8] ack-connect-route-final --- ack-connect-route/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ack-connect-route/README.md b/ack-connect-route/README.md index 0988398e5..01410edaf 100644 --- a/ack-connect-route/README.md +++ b/ack-connect-route/README.md @@ -59,7 +59,7 @@ Once the application is deployed, retrieve the WebSocketURL value from CloudForm ``` $ wscat -c connected (press CTRL+C to quit) - +``` ## Cleanup 1. Delete the stack From 79ec4deb37a6cd3b5e7b9877c6fa6e5175854d17 Mon Sep 17 00:00:00 2001 From: Manasvi Jain Date: Wed, 24 Jul 2024 11:31:25 +0530 Subject: [PATCH 8/8] apigw-websocket-api-vpclink --- apigw-websocket-api-vpclink/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/apigw-websocket-api-vpclink/README.md b/apigw-websocket-api-vpclink/README.md index 98087b152..69049d8d4 100644 --- a/apigw-websocket-api-vpclink/README.md +++ b/apigw-websocket-api-vpclink/README.md @@ -60,8 +60,6 @@ Once the application is deployed, retrieve the WebSocketURL value from CloudForm ``` $ wscat -c connected (press CTRL+C to quit) -> {"action":"post", "data":"hello world"} -< hello world ``` ## Cleanup