Monitoring tools that notify you of any changes in your favorite web pages.
Invoking function locally using a local sample payload
sam build
sam local invoke FUNCTION_NAME --event event.json
Firstly, we need a S3 bucket
where we can upload our Lambda functions packaged as ZIP before we deploy anything - If you don't have a S3 bucket to store code artifacts then this is a good time to create one:
aws s3 mb s3://BUCKET_NAME
Next, run the following command to package our Lambda function to S3:
sam package \
--output-template-file packaged.yaml \
--s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME
Next, the following command will create a Cloudformation Stack and deploy your SAM resources.
sam deploy \
--template-file packaged.yaml \
--stack-name yoppinews-web-monitor-bot \
--capabilities CAPABILITY_IAM
See Serverless Application Model (SAM) HOWTO Guide for more details in how to get started.
After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL:
aws cloudformation describe-stacks \
--stack-name yoppinews-web-monitor-bot \
--query 'Stacks[].Outputs[?OutputKey==`HelloWorldApi`]' \
--output table
To simplify troubleshooting, SAM CLI has a command called sam logs. sam logs lets you fetch logs generated by your Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
NOTE
: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
sam logs -n HelloWorldFunction --stack-name yoppinews-web-monitor-bot --tail
You can find more information and examples about filtering Lambda function logs in the SAM CLI Documentation.
Next, we install test dependencies and we run pytest
against our tests
folder to run our initial unit tests:
pip install pytest pytest-mock --user
python -m pytest tests/ -v
In order to delete our Serverless Application recently deployed you can use the following AWS CLI Command:
aws cloudformation delete-stack --stack-name yoppinews-web-monitor-bot