Skip to content

Commit e6fe18c

Browse files
author
joaumann
committed
Inital Commit for apigw-http-lambda-documentdb Pattern
1 parent a140875 commit e6fe18c

File tree

10 files changed

+297
-0
lines changed

10 files changed

+297
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# AWS Service 1 to AWS Service 2
2+
3+
This pattern << explain usage >>
4+
5+
Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >>
6+
7+
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.
8+
9+
## Requirements
10+
11+
* [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.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
16+
## Deployment Instructions
17+
18+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
19+
```bash
20+
git clone https://github.com/aws-samples/serverless-patterns
21+
```
22+
1. Change directory to the pattern directory:
23+
```bash
24+
cd apigw-http-lambda-documentdb-cdk
25+
```
26+
1. run npm install to install npm packages:
27+
```bash
28+
npm install
29+
```
30+
1. From the command line, configure AWS CDK with
31+
```bash
32+
cdk bootstrap
33+
```
34+
6. From the command line, use AWS CDK to deploy the AWS resources for the pattern as specified in the `lib/cdk-stack.ts` file:
35+
```bash
36+
cdk deploy
37+
```
38+
## How it works
39+
40+
Explain how the service interaction works.
41+
42+
## Testing
43+
44+
Provide steps to trigger the integration and show what should be observed if successful.
45+
46+
## Cleanup
47+
48+
1. Delete the stack
49+
```bash
50+
aws cloudformation delete-stack --stack-name STACK_NAME
51+
```
52+
1. Confirm the stack has been deleted
53+
```bash
54+
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
55+
```
56+
----
57+
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
58+
59+
SPDX-License-Identifier: MIT-0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { ApiGwHttpLambdaDocumentDbStack } from '../lib/apigw-http-lambda-documentdb-stack';
5+
6+
const app = new cdk.App();
7+
8+
new ApiGwHttpLambdaDocumentDbStack(app, 'ApiGwHttpLambdaDocumentDbStack');
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/apigw-http-lambda-documentdb.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48+
"@aws-cdk/aws-redshift:columnId": true,
49+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
51+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52+
"@aws-cdk/aws-kms:aliasNameRef": true,
53+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
56+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
60+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true
62+
}
63+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"title": "Amazon API Gateway to AWS Lambda to Amazon DocumentDB ",
3+
"description": "Create an Amazon API Gateway HTTP API to invoke a Lambda function to read and write to DocumentDB.",
4+
"language": "TypeScript",
5+
"level": "200",
6+
"framework": "CDK",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This sample project demonstrates how to use an AWS Step Functions state machine to query Athena and get the results. This pattern is leveraging the native integration between these 2 services which means only JSON-based, structured language is used to define the implementation.",
11+
"With Amazon Athena you can get up to 1000 results per invocation of the GetQueryResults method and this is the reason why the Step Function has a loop to get more results. The results are sent to a Map which can be configured to handle (the DoSomething state) the items in parallel or one by one by modifying the max_concurrency parameter.",
12+
"This pattern deploys one Step Functions, two S3 Buckets, one Glue table and one Glue database."
13+
]
14+
},
15+
"gitHub": {
16+
"template": {
17+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-http-lambda-documentdb-cdk",
18+
"templateURL": "serverless-patterns/apigw-http-lambda-documentdb-cdk",
19+
"projectFolder": "apigw-http-lambda-documentdb-cdk",
20+
"templateFile": "sfn_athena_cdk_python/sfn_athena_cdk_python_stack.py"
21+
}
22+
},
23+
"resources": {
24+
"bullets": [
25+
{
26+
"text": "Call Athena with Step Functions",
27+
"link": "https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html"
28+
},
29+
{
30+
"text": "Amazon Athena - Serverless Interactive Query Service",
31+
"link": "https://aws.amazon.com/athena/"
32+
}
33+
]
34+
},
35+
"deploy": {
36+
"text": [
37+
"sam deploy"
38+
]
39+
},
40+
"testing": {
41+
"text": [
42+
"See the GitHub repo for detailed testing instructions."
43+
]
44+
},
45+
"cleanup": {
46+
"text": [
47+
"Delete the stack: <code>cdk delete</code>."
48+
]
49+
},
50+
"authors": [
51+
{
52+
"name": "Joachim Aumann",
53+
"image": "link-to-your-photo.jpg",
54+
"bio": "Your bio.",
55+
"linkedin": "https://www.linkedin.com/in/joachim-aumann/"
56+
}
57+
]
58+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
// import * as sqs from 'aws-cdk-lib/aws-sqs';
4+
5+
export class ApiGwHttpLambdaDocumentDbStack extends cdk.Stack {
6+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
7+
super(scope, id, props);
8+
9+
// The code that defines your stack goes here
10+
11+
// example resource
12+
// const queue = new sqs.Queue(this, 'TempQueue', {
13+
// visibilityTimeout: cdk.Duration.seconds(300)
14+
// });
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "apigw-http-lambda-documentdb-cdk",
3+
"version": "0.1.0",
4+
"bin": {
5+
"temp": "bin/temp.js"
6+
},
7+
"scripts": {
8+
"build": "tsc",
9+
"watch": "tsc -w",
10+
"test": "jest",
11+
"cdk": "cdk"
12+
},
13+
"devDependencies": {
14+
"@types/jest": "^29.5.5",
15+
"@types/node": "20.7.1",
16+
"jest": "^29.7.0",
17+
"ts-jest": "^29.1.1",
18+
"aws-cdk": "2.103.1",
19+
"ts-node": "^10.9.1",
20+
"typescript": "~5.2.2"
21+
},
22+
"dependencies": {
23+
"aws-cdk-lib": "2.103.1",
24+
"constructs": "^10.0.0",
25+
"source-map-support": "^0.5.21"
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* SPDX-License-Identifier: MIT-0
3+
*/
4+
5+
'use strict'
6+
7+
exports.handler = async (event) => {
8+
// Lambda handler code
9+
console.log(JSON.stringify(event, 0, null))
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// import * as cdk from 'aws-cdk-lib';
2+
// import { Template } from 'aws-cdk-lib/assertions';
3+
// import * as Temp from '../lib/temp-stack';
4+
5+
// example test. To run these tests, uncomment this file along with the
6+
// example resource in lib/temp-stack.ts
7+
test('SQS Queue Created', () => {
8+
// const app = new cdk.App();
9+
// // WHEN
10+
// const stack = new Temp.TempStack(app, 'MyTestStack');
11+
// // THEN
12+
// const template = Template.fromStack(stack);
13+
14+
// template.hasResourceProperties('AWS::SQS::Queue', {
15+
// VisibilityTimeout: 300
16+
// });
17+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "commonjs",
5+
"lib": [
6+
"es2020",
7+
"dom"
8+
],
9+
"declaration": true,
10+
"strict": true,
11+
"noImplicitAny": true,
12+
"strictNullChecks": true,
13+
"noImplicitThis": true,
14+
"alwaysStrict": true,
15+
"noUnusedLocals": false,
16+
"noUnusedParameters": false,
17+
"noImplicitReturns": true,
18+
"noFallthroughCasesInSwitch": false,
19+
"inlineSourceMap": true,
20+
"inlineSources": true,
21+
"experimentalDecorators": true,
22+
"strictPropertyInitialization": false,
23+
"typeRoots": [
24+
"./node_modules/@types"
25+
]
26+
},
27+
"exclude": [
28+
"node_modules",
29+
"cdk.out"
30+
]
31+
}

0 commit comments

Comments
 (0)