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

My first Typescript Lambda #2043

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 70 additions & 0 deletions .github/workflows/typescriptLambdaHelloWorld.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build typescript-lambda-hello-world

on:
- push

jobs:
CI:
if: github.repository_owner == 'guardian'
# Required by actions-assume-aws-role
permissions:
id-token: write
contents: read
name: typescript-lambda-hello-world build
runs-on: ubuntu-latest
steps:
- name: Env
run: env

- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: 'handlers/TypescriptHelloWorld1/.nvmrc'
cache: 'yarn'
cache-dependency-path: handlers/TypescriptHelloWorld1/yarn.lock

- name: Yarn
run: |
yarn install
yarn run build
working-directory: handlers/TypescriptHelloWorld1

- name: Copy files to Riff Raff package
run: cp package.json riff-raff.yaml dist
working-directory: handlers/TypescriptHelloWorld1

- name: Zip target directory contents (quietly)
run: zip -qr ../typescript-lambda-hello-world.zip ./*
working-directory: handlers/TypescriptHelloWorld1/dist

- name: Yarn (CDK)
working-directory: cdk
run: |
yarn install
yarn tsc
yarn lint
yarn test

- name: Yarn synth (CDK)
working-directory: cdk
run: yarn synth

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.GU_RIFF_RAFF_ROLE_ARN }}

- name: Upload to Riff-Raff
uses: guardian/actions-riff-raff@v2
with:
app: typescript-lambda-hello-world
configPath: handlers/TypescriptHelloWorld1/riff-raff.yaml
contentDirectories: |
typescript-lambda-hello-world-cloudformation:
- ./cdk/cdk.out/typescript-lambda-hello-world-DEV.template.json
typescript-lambda-hello-world:
- handlers/TypescriptHelloWorld1/typescript-lambda-hello-world.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
target/
cdk-cfn.yaml
metals.sbt
node_modules/
5 changes: 4 additions & 1 deletion cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "source-map-support/register";
import { App } from "aws-cdk-lib";
import type { NewProductApiProps } from "../lib/new-product-api";
import { NewProductApi } from "../lib/new-product-api";
import { TypescriptLambdaHelloWorld } from "../lib/typescript-lambda-hello-world";

const app = new App();

Expand All @@ -28,4 +29,6 @@ export const prodProps: NewProductApiProps = {
};

new NewProductApi(app, "new-product-api-CODE", codeProps);
new NewProductApi(app, "new-product-api-PROD", prodProps);
new NewProductApi(app, "new-product-api-PROD", prodProps);

new TypescriptLambdaHelloWorld(app, "typescript-lambda-hello-world-DEV", {stack: "membership", stage: "DEV"});
29 changes: 29 additions & 0 deletions cdk/lib/typescript-lambda-hello-world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//import { join } from 'path';
import { GuScheduledLambda } from '@guardian/cdk';
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
import { GuStack } from '@guardian/cdk/lib/constructs/core';
import type { App } from 'aws-cdk-lib';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

export class TypescriptLambdaHelloWorld extends GuStack {
constructor(scope: App, id: string, props: GuStackProps) {
super(scope, id, props);

const app = 'typescript-lambda-hello-world';
const nationalDeliveryFulfilmentLambda = new GuScheduledLambda(
this,
'typescript-lambda-hello-world',
{
description: 'A first effort at making a typescript lamba',
functionName: `membership-typescript-lambda-hello-world-DEV`,
handler: 'typescript-lambda-hello-world/index.main',
runtime: Runtime.NODEJS_18_X,
memorySize: 1024,
fileName: `typescript-lambda-hello-world.zip`,
app: app,
rules: [],
monitoringConfiguration: { noMonitoring: true },
},
);
}
}
207 changes: 207 additions & 0 deletions handlers/TypescriptHelloWorld1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@

# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env*.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Storybook build outputs
.out
.storybook-out
storybook-static

# rollup.js default build output
dist/

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Temporary folders
tmp/
temp/

### OSX ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### SAM ###
# Ignore build directories for the AWS Serverless Application Model (SAM)
# Info: https://aws.amazon.com/serverless/sam/
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html

**/.aws-sam

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
Expand Down
1 change: 1 addition & 0 deletions handlers/TypescriptHelloWorld1/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
Loading