-
Notifications
You must be signed in to change notification settings - Fork 9
created a lambda function 8d #9
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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('------------------------------'); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.