Skip to content

Commit

Permalink
chore: Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pgollucci committed Oct 25, 2024
0 parents commit 7f5d110
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.aws-sam/
.DS_Store
.pnp.cjs
.pnp.loader.mjs
.yarn/
coverage/
dist/
logs
node_modules/
yarn.lock
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.18.0
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"foxundermoon.shell-format",
"orta.vscode-jest",
"vscode.json-language-features",
"vscode.typescript-language-features"
]
}
52 changes: 52 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"[ignore]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[dotenv]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
"source.organizeImports": "never"
},
"eslint.validate": [
"javascript",
"typescript",
"markdown",
"json",
"jsonc",
"yaml",
"xml",
"html"
],
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.format.enable": false,
"jest.runMode": "on-demand",
"editor.tabSize": 2,
"explorer.excludeGitIgnore": false,
"files.exclude": {
"**/.git": false,
"**/.gitignore": false,
"node_modules": true,
"dist": true,
".cache": true
},
"files.associations": {
"*.test.ts": "typescript"
},
"typescript.suggest.autoImports": true,
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.referencesCodeLens.enabled": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
}
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
14 changes: 14 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as process from 'node:process'
import esbuild from 'esbuild'

esbuild.build({
entryPoints: ['./src/lambda.ts'],
bundle: true,
platform: 'node',
target: ['node20'],
outdir: './dist',
sourcemap: true,
minify: false,
external: ['aws-sdk'],
logLevel: 'info',
}).catch(() => process.exit(1))
21 changes: 21 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import antfu from '@antfu/eslint-config'

export default antfu({
ignores: [
'.pnpm-store/',
'.vscode/',
'events/',
'package.json',
'samconfig.toml',
'template.yaml',
'tsconfig.json',
],
plugins: {
},
languageOptions: {
},
rules: {
},
settings: {
},
})
7 changes: 7 additions & 0 deletions events/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"httpMethod": "POST",
"body": "{\"filename\": \"testfile.jpg\"}",
"headers": {
"Content-Type": "application/json"
}
}
19 changes: 19 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Config } from 'jest'

const customJestConfig: Config = {
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
testMatch: ['<rootDir>/test/**/*.test.ts}'],
testPathIgnorePatterns: ['/node_modules/'],

transform: {
'^.+\\.(ts)$': '@swc/jest',
},
collectCoverage: true,
coverageDirectory: 'coverage',
moduleFileExtensions: ['ts', 'js'],
}

export default customJestConfig
61 changes: 61 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "p6-
"description": "APIGW Receiver Serverless Image Brander for LDAR Pets",
"repository": {
"type": "git",
"url": "https://github.com/luckydoganimalrescue/p6-ldar-cdk-pnp-brand-image.git"
},
"version": "0.3.0",
"author": {
"name": "Philip M. Gollucci",
"email": "pgollucci@p6m7g8.com",
"url": "https://www.linkedin.com/in/pgollucci",
"organization": true
},
"keywords": [
"aws",
"lambda",
"samcli"
],
"engines": {
"node": ">= 20.10.18"
},
"license": "Apache-2.0",
"type": "module",
"main": "src/lambda.ts",
"scripts": {
"all": "yarn nuke && yarn install && yarn docker && yarn sam:container && yarn run ci",
"bundle": "node --trace-deprecation esbuild.config.mjs",
"ci": "yarn run lint && yarn run test && yarn run bundle",
"docker": "docker run -it --rm -v $(pwd):/app -w /app node:20 bash -c \"rm -rf node_modules && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 CI=1 corepack enable && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 CI=1 yarn install\"",
"nuke": "rm -rf .aws-sam coverage dist node_modules .yarn",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"sam:container": "sam build --use-container",
"sam:start:api": "yarn run ci && sam local start-api --port 3001 --debug",
"sam:invoke:X": "yarn run ci && sam local invoke XFunction --event events/brand.json",
"test": "node --trace-deprecation ./node_modules/jest/bin/jest.js --config jest.config.ts --coverage --passWithNoTests",
"test:watch": "node --trace-deprecation ./node_modules/jest/bin/jest.js --config jest.config.ts --watch --coverage",
"type": "tsc --noEmit"
},
"dependencies": {
"aws-lambda": "^1.0.7"
},
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@swc/jest": "^0.2.36",
"@types/aws-lambda": "^8.10.145",
"@types/jest": "^29.5.14",
"@types/node": "^22.7.9",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"esbuild": "^0.24.0",
"eslint": "^9.13.0",
"eslint-plugin-import": "^2.31.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
},
"packageManager": "yarn@4.5.1"
}
5 changes: 5 additions & 0 deletions samconfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version = 0.1

[default.deploy]

[default.package]
19 changes: 19 additions & 0 deletions src/lambda.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Context } from 'aws-lambda'
import * as process from 'node:process'

export const handler = async (
event,
_context: Context,
): => {
const body = JSON.parse(event.body || '{]')

return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
},
body: JSON.stringify({ x }),
}
}
29 changes: 29 additions & 0 deletions template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "'OPTIONS,GET,POST'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"

XFunction:
Type: AWS::Serverless::Function
Properties:
Handler: dist/X.handler
Runtime: nodejs20.x
CodeUri: ./dist
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /X
Method: post

XunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/XFunctionLogGroup
RetentionInDays: 14
40 changes: 40 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"compilerOptions": {
"incremental": true,
"target": "ESNext",
"lib": [
"esnext"
],
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": [
"node",
"jest"
],
"allowJs": false,
"strict": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
"useUnknownInCatchVariables": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"skipLibCheck": true
},
"include": [
"jest.config.ts",
"src/**/*.ts",
"test/**/*.ts",
],
"exclude": [
"dist",
"node_modules"
]
}

0 comments on commit 7f5d110

Please sign in to comment.