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.
You can test the Lambda function locally before deployment using yarn lambda:dev,
Then install all necessary packages using yarn install.
- Go to the AWS Lambda Console: https://console.aws.amazon.com/lambda
- Log in your AWS account.
- Create a function by selecting 'Author from scratch', entering a function name, and selecting runtime.
- Upload your FunctionCode.zip.
- Click Deploy.
- Go to Configuration -> Triggers.
- Select 'API Gateway' and choose to create a new API.
- Set Deployment Stage then click 'Add'.
- Go to your API -> Stages -> YOUR_DEPLOYMENT_STAGE.
- Copy and paste the Invoke URL to your browser to test.
-
Zip your Lambda Function Code.
-
Deploy the Lambda Function by running the following command to create the function:.
aws lambda create-function --function-name <YOUR_FUNCTION> \ -
Create an API Gateway:
aws apigateway create-rest-api --name <YOUR_API_NAME> -
Get the Root Resource ID of the new API:
aws apigateway get-resources --rest-api-id <API_ID> -
Create a new resource in the API Gateway:
aws apigateway create-resource --rest-api-id <API_ID> \ -
Create a GET method that triggers Lambda:
aws apigateway put-method --rest-api-id <API_ID> \ -
Link the method to the Lambda Function:
aws apigateway put-integration --rest-api-id <API_ID> \ -
Deploy the API Gateway and get the Invoke URL:
aws apigateway create-deployment --rest-api-id <API_ID> \ -
Allow API Gateway to invoke your Lambda Function:
aws lambda add-permission --function-name <YOUR_FUNCTION> \ -
Update the function code for later use by running this code:
aws lambda update-function-code --function-name <YOUR_FUNCTION> \ -
Verify the deployment using this code:
aws lambda invoke --function-name <YOUR_FUNCTION> output.txtOR:curl -X POST "https://<API_ID>.execute-api.<REGION>.amazonaws.com/prod/lambda"