|
| 1 | +# AWS Lambda Deployment Guide |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before deploying, ensure you have the following: |
| 8 | +- **AWS Account** with access to **AWS Lambda** and **API Gateway**, as well as with necessary IAM Role Permissions. |
| 9 | +- **AWS CLI** installed and configured (`aws configure`). |
| 10 | +- **Yarn** installed (`npm install -g yarn`). |
| 11 | +- **API Gateway** configured to trigger the Lambda function. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Test Running Locally |
| 16 | + |
| 17 | +You can test the Lambda function locally before deployment using `yarn lambda:dev`, |
| 18 | +Then install all necessary packages using `yarn install`. |
| 19 | + |
| 20 | + |
| 21 | +## Deploying to AWS (using AWS Website) |
| 22 | + |
| 23 | +1. Go to the AWS Lambda Console: https://console.aws.amazon.com/lambda |
| 24 | +2. Log in your AWS account. |
| 25 | +3. Create a function by selecting 'Author from scratch', entering a function name, and selecting runtime. |
| 26 | +4. Upload your FunctionCode.zip. |
| 27 | +5. Click Deploy. |
| 28 | +6. Go to Configuration -> Triggers. |
| 29 | +7. Select 'API Gateway' and choose to create a new API. |
| 30 | +8. Set Deployment Stage then click 'Add'. |
| 31 | +9. Go to your API -> Stages -> YOUR_DEPLOYMENT_STAGE. |
| 32 | +10. Copy and paste the Invoke URL to your browser to test. |
| 33 | + |
| 34 | + |
| 35 | +## Deploying to AWS (using AWS CLI) |
| 36 | + |
| 37 | +1. Zip your Lambda Function Code. |
| 38 | +2. Deploy the Lambda Function by running the following command to create the function:. |
| 39 | +`aws lambda create-function --function-name <YOUR_FUNCTION> \` |
| 40 | + |
| 41 | +3. Create an API Gateway: |
| 42 | +`aws apigateway create-rest-api --name <YOUR_API_NAME>` |
| 43 | + |
| 44 | +4. Get the Root Resource ID of the new API: |
| 45 | +`aws apigateway get-resources --rest-api-id <API_ID>` |
| 46 | + |
| 47 | +5. Create a new resource in the API Gateway: |
| 48 | +`aws apigateway create-resource --rest-api-id <API_ID> \` |
| 49 | + |
| 50 | +6. Create a GET method that triggers Lambda: |
| 51 | +`aws apigateway put-method --rest-api-id <API_ID> \` |
| 52 | + |
| 53 | +7. Link the method to the Lambda Function: |
| 54 | +`aws apigateway put-integration --rest-api-id <API_ID> \` |
| 55 | + |
| 56 | +8. Deploy the API Gateway and get the Invoke URL: |
| 57 | +`aws apigateway create-deployment --rest-api-id <API_ID> \` |
| 58 | + |
| 59 | +9. Allow API Gateway to invoke your Lambda Function: |
| 60 | +`aws lambda add-permission --function-name <YOUR_FUNCTION> \` |
| 61 | + |
| 62 | +10. Update the function code for later use by running this code: |
| 63 | +`aws lambda update-function-code --function-name <YOUR_FUNCTION> \` |
| 64 | + |
| 65 | +11. Verify the deployment using this code: |
| 66 | +`aws lambda invoke --function-name <YOUR_FUNCTION> output.txt` |
| 67 | +OR: |
| 68 | +`curl -X POST "https://<API_ID>.execute-api.<REGION>.amazonaws.com/prod/lambda"` |
0 commit comments