Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Lambda adapter #182

Merged
merged 68 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0b07be2
Fix
raviqqe Dec 13, 2023
107f836
Install aws-lambda
raviqqe Dec 13, 2023
4194408
Fix
raviqqe Dec 13, 2023
ef204b1
Fix
raviqqe Dec 13, 2023
9771b4c
Fix
raviqqe Dec 14, 2023
bfed765
Fix
raviqqe Dec 14, 2023
2a719e1
Merge branch 'main' into feature/aws-lambda-adapter
raviqqe Dec 14, 2023
56f7e6f
Fix
raviqqe Dec 15, 2023
caf610e
Merge branch 'main' into feature/aws-lambda-adapter
raviqqe Dec 15, 2023
8046d32
Fix
raviqqe Dec 16, 2023
10445bf
Merge branch 'main' into feature/aws-lambda-adapter
raviqqe Dec 16, 2023
555bdfe
Fix
raviqqe Dec 16, 2023
d887cba
Fix
raviqqe Dec 16, 2023
bc1e09f
Fix
raviqqe Dec 16, 2023
493c95b
Fix
raviqqe Dec 16, 2023
2f9d8dd
Fix
raviqqe Dec 16, 2023
197f368
Fix
raviqqe Dec 16, 2023
39ed4f5
WIP
raviqqe Dec 16, 2023
7f41d4d
Update lock file
raviqqe Dec 16, 2023
8f0eac1
Fix
raviqqe Dec 16, 2023
c86f5dd
Fix linting
raviqqe Dec 16, 2023
9bd1843
Remove tests
raviqqe Dec 16, 2023
197ec9e
Fix
raviqqe Dec 16, 2023
b28eede
Fix
raviqqe Dec 16, 2023
b6ad1e2
Update
raviqqe Dec 16, 2023
2fd3c92
Fix
raviqqe Dec 16, 2023
6b6787f
Fix
raviqqe Dec 16, 2023
8c91bfe
Fix
raviqqe Dec 16, 2023
de9c36e
Fix linting
raviqqe Dec 16, 2023
c18219b
Fix
raviqqe Dec 16, 2023
0cd040d
Fix
raviqqe Dec 16, 2023
6d186f4
Fix
raviqqe Dec 16, 2023
a1cfb0c
Fix
raviqqe Dec 16, 2023
f983113
Fix
raviqqe Dec 16, 2023
9eb8930
Fix
raviqqe Dec 16, 2023
ddf7fb3
Fix
raviqqe Dec 16, 2023
a1ac367
Fix
raviqqe Dec 16, 2023
fa7801d
Fix
raviqqe Dec 16, 2023
5d8662c
Fix
raviqqe Dec 16, 2023
5944760
Fix
raviqqe Dec 16, 2023
7430d70
Fix
raviqqe Dec 16, 2023
c61673c
Fix
raviqqe Dec 16, 2023
d710453
Fix
raviqqe Dec 16, 2023
6d9a4f5
Fix
raviqqe Dec 16, 2023
d362297
Fix
raviqqe Dec 16, 2023
f27dabc
Fix
raviqqe Dec 16, 2023
86ff910
Fix
raviqqe Dec 16, 2023
d421134
Fix
raviqqe Dec 16, 2023
118e6d4
Fix
raviqqe Dec 16, 2023
c297a55
Fix
raviqqe Dec 16, 2023
aac4d17
Fix
raviqqe Dec 16, 2023
e3b5c1b
Fix
raviqqe Dec 16, 2023
03caa5d
Disable cache
raviqqe Dec 16, 2023
fe10068
Fix authentication type of function URL
raviqqe Dec 17, 2023
981bd4e
Fix
raviqqe Dec 17, 2023
6b8baa2
Fix
raviqqe Dec 17, 2023
5e02b17
Fix
raviqqe Dec 17, 2023
f09dd43
Disable minify
raviqqe Dec 17, 2023
aab3c08
Fix
raviqqe Dec 17, 2023
2f0c9f3
Simplify bundle
raviqqe Dec 17, 2023
b3077d7
Fix
raviqqe Dec 17, 2023
ec35546
Fix
raviqqe Dec 17, 2023
ac766ec
Fix
raviqqe Dec 17, 2023
a54852f
Fix
raviqqe Dec 17, 2023
438ae9d
Fix
raviqqe Dec 17, 2023
11c4753
Fix
raviqqe Dec 17, 2023
d2f4f5d
Remove context
raviqqe Dec 17, 2023
33b00a5
Fix
raviqqe Dec 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: latest
cache: npm
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm run test
- run: npm run -ws build
- run: npm run -ws lint
- run: npm run -ws test
- uses: codecov/codecov-action@v3
spell_check:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions examples/aws/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.cdk.staging
cdk.out
10 changes: 10 additions & 0 deletions examples/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# AWS Lambda example

This is an example usage of `onerpc` deployed as a AWS Lambda function using AWS CDK.

## Usage

```sh
npx cdk deploy
curl -fsS https://<cf-output-domain>.cloudfront.net
```
46 changes: 46 additions & 0 deletions examples/aws/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"app": "tsx src/main.ts",
"watch": { "include": ["src/**/*.ts"] },
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
}
}
10 changes: 10 additions & 0 deletions examples/aws/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import configurations from "@raviqqe/eslint-config";

export default [
...configurations,
{
rules: {
"import/extensions": "off",
},
},
];
23 changes: 23 additions & 0 deletions examples/aws/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "aws",
"version": "0.1.0",
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint src",
"test": "vitest"
},
"dependencies": {
"aws-cdk-lib": "^2.115.0",
"constructs": "^10.0.0",
"onerpc": "../..",
"valibot": "^0.24.1"
},
"devDependencies": {
"@raviqqe/eslint-config": "^2.0.4",
"@raviqqe/tsconfig": "^1.0.8",
"aws-cdk": "^2.115.0",
"tsx": "^4.6.2",
"typescript": "^5.3.3"
}
}
7 changes: 7 additions & 0 deletions examples/aws/src/lambda/square.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { query } from "onerpc";
import { awsLambda } from "onerpc/adapter/aws-lambda";
import { number } from "valibot";

export const handler = awsLambda(
query(number(), number(), (input) => input * input),
);

Check warning on line 7 in examples/aws/src/lambda/square.ts

View check run for this annotation

Codecov / codecov/patch

examples/aws/src/lambda/square.ts#L2-L7

Added lines #L2 - L7 were not covered by tests
3 changes: 3 additions & 0 deletions examples/aws/src/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { it } from "vitest";

it("passes", () => {});
4 changes: 4 additions & 0 deletions examples/aws/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { App } from "aws-cdk-lib";
import { MainStack } from "./stack.js";

new MainStack(new App(), "Stack");

Check warning on line 4 in examples/aws/src/main.ts

View check run for this annotation

Codecov / codecov/patch

examples/aws/src/main.ts#L2-L4

Added lines #L2 - L4 were not covered by tests
37 changes: 37 additions & 0 deletions examples/aws/src/stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CfnOutput, Fn, Stack, type StackProps } from "aws-cdk-lib";
import {
AllowedMethods,
CachePolicy,
Distribution,
OriginRequestPolicy,
} from "aws-cdk-lib/aws-cloudfront";
import { HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
import { FunctionUrlAuthType, Runtime } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import { type Construct } from "constructs";

export class MainStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const lambda = new NodejsFunction(this, "Function", {
entry: "src/lambda/square.ts",
runtime: Runtime.NODEJS_LATEST,
});
const url = lambda.addFunctionUrl({ authType: FunctionUrlAuthType.NONE });

const distribution = new Distribution(this, "Distribution", {
defaultBehavior: {
allowedMethods: AllowedMethods.ALLOW_ALL,
cachePolicy: CachePolicy.CACHING_DISABLED,
origin: new HttpOrigin(Fn.parseDomainName(url.url)),
originRequestPolicy: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
},
enableLogging: true,
});

new CfnOutput(this, "Domain", {
value: distribution.domainName,
});
}
}

Check warning on line 37 in examples/aws/src/stack.ts

View check run for this annotation

Codecov / codecov/patch

examples/aws/src/stack.ts#L2-L37

Added lines #L2 - L37 were not covered by tests
8 changes: 8 additions & 0 deletions examples/aws/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["@raviqqe/tsconfig/tsconfig.json"],
"compilerOptions": {
"noEmit": true,
"rootDir": "src"
},
"include": ["src"]
}
Loading