Skip to content
Merged
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
68 changes: 68 additions & 0 deletions examples/with-lambda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# AWS Lambda Deployment Guide

---

## Prerequisites

Before deploying, ensure you have the following:
- **AWS Account** with access to **AWS Lambda** and **API Gateway**, as well as with necessary IAM Role Permissions.
- **AWS CLI** installed and configured (`aws configure`).
- **Yarn** installed (`npm install -g yarn`).
- **API Gateway** configured to trigger the Lambda function.

---

## Test Running Locally

You can test the Lambda function locally before deployment using `yarn lambda:dev`,
Then install all necessary packages using `yarn install`.


## Deploying to AWS (using AWS Website)

1. Go to the AWS Lambda Console: https://console.aws.amazon.com/lambda
2. Log in your AWS account.
3. Create a function by selecting 'Author from scratch', entering a function name, and selecting runtime.
4. Upload your FunctionCode.zip.
5. Click Deploy.
6. Go to Configuration -> Triggers.
7. Select 'API Gateway' and choose to create a new API.
8. Set Deployment Stage then click 'Add'.
9. Go to your API -> Stages -> YOUR_DEPLOYMENT_STAGE.
10. Copy and paste the Invoke URL to your browser to test.


## Deploying to AWS (using AWS CLI)

1. Zip your Lambda Function Code.
2. Deploy the Lambda Function by running the following command to create the function:.
`aws lambda create-function --function-name <YOUR_FUNCTION> \`

3. Create an API Gateway:
`aws apigateway create-rest-api --name <YOUR_API_NAME>`

4. Get the Root Resource ID of the new API:
`aws apigateway get-resources --rest-api-id <API_ID>`

5. Create a new resource in the API Gateway:
`aws apigateway create-resource --rest-api-id <API_ID> \`

6. Create a GET method that triggers Lambda:
`aws apigateway put-method --rest-api-id <API_ID> \`

7. Link the method to the Lambda Function:
`aws apigateway put-integration --rest-api-id <API_ID> \`

8. Deploy the API Gateway and get the Invoke URL:
`aws apigateway create-deployment --rest-api-id <API_ID> \`

9. Allow API Gateway to invoke your Lambda Function:
`aws lambda add-permission --function-name <YOUR_FUNCTION> \`

10. Update the function code for later use by running this code:
`aws lambda update-function-code --function-name <YOUR_FUNCTION> \`

11. Verify the deployment using this code:
`aws lambda invoke --function-name <YOUR_FUNCTION> output.txt`
OR:
`curl -X POST "https://<API_ID>.execute-api.<REGION>.amazonaws.com/prod/lambda"`
26 changes: 26 additions & 0 deletions examples/with-lambda/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { server } from '@stackpress/ingest/fetch';
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';

// server starter
const app = server();

app.get("/", (req, res) => {
res.setHTML('<h1>Hello, World from Lambda!</h1>');
});

// AWS Lambda handler
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
return {
statusCode: 200,
headers: { "Content-Type": "text/html" },
body: '<h1>Hello, World from Lambda!</h1>',
};
};

// local server starter for testing
if (process.env.LAMBDA_LOCAL === 'true') {
app.create().listen(3000, () => {
console.log('Server is running on port 3000');
console.log('------------------------------');
});
}
22 changes: 22 additions & 0 deletions examples/with-lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ingest-with-lambda",
"version": "1.0.0",
"description": "A simple boilerplate for using Ingest with Lambda.",
"private": true,
"scripts": {
"build": "tsc",
"dev": "LAMBDA_LOCAL=true ts-node index.ts"
},
"dependencies": {
"@stackpress/ingest": "^0.3.27",
"@types/aws-lambda": "^8.10.147",
"@whatwg-node/server": "^0.9.67",
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/node": "^22.13.1",
"serverless-offline": "^14.4.0",
"ts-node": "10.9.2",
"typescript": "^4.9.5"
}
}
20 changes: 20 additions & 0 deletions examples/with-lambda/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"lib": ["es2021", "es7", "es6", "dom"],
"module": "commonjs",
"noUnusedLocals": true,
"outDir": "./dist/",
"preserveConstEnums": true,
"resolveJsonModule": true,
"removeComments": true,
"sourceMap": false,
"strict": true,
"target": "es2017",
"skipLibCheck": true
},
"include": ["src/**/*.ts", "index.ts"],
"exclude": ["dist", "node_modules"]
}

4 changes: 2 additions & 2 deletions examples/with-netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ingest-with-fetch",
"name": "ingest-with-netlify",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. thanks for this.

"version": "1.0.0",
"description": "A simple boilerplate for using Ingest with fetch API.",
"description": "A simple boilerplate for using Ingest with Netlify",
"private": true,
"scripts": {
"build": "tsc",
Expand Down
Loading