File tree Expand file tree Collapse file tree 9 files changed +88
-0
lines changed
Expand file tree Collapse file tree 9 files changed +88
-0
lines changed File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ export AWS_ACCESS_KEY_ID ?= test
2+ export AWS_SECRET_ACCESS_KEY ?= test
3+ export AWS_DEFAULT_REGION = us-east-1
4+
5+ usage : # # Show this help
6+ @fgrep -h " ##" $(MAKEFILE_LIST ) | fgrep -v fgrep | sed -e ' s/\\$$//' | sed -e ' s/##//'
7+
8+ install : # # Install dependencies
9+ @which awslocal || pip install awscli-local
10+
11+ run : # # Build, deploy, and invoke the Lambda function URL
12+ npm i -g zip
13+ pip3 install -r requirements.txt -t .
14+ zip -r function.zip .
15+ awslocal lambda create-function \
16+ --function-name trending \
17+ --runtime python3.9 \
18+ --timeout 10 \
19+ --zip-file fileb://function.zip \
20+ --handler lambda_function.lambda_handler \
21+ --role cool-stacklifter
22+
23+ awslocal lambda create-function-url-config \
24+ --function-name trending \
25+ --auth-type NONE
26+
27+ start :
28+ localstack start -d
29+
30+ stop :
31+ @echo
32+ localstack stop
33+
34+ ready :
35+ @echo Waiting on the LocalStack container...
36+ @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
37+
38+ logs :
39+ @localstack logs > logs.txt
40+
41+ test-ci :
42+ make start install ready run; return_code=` echo $$ ? ` ; \
43+ make logs; make stop; exit $$ return_code;
44+
45+ .PHONY : usage install start run stop ready logs test-ci
Original file line number Diff line number Diff line change 1+ import json
2+ import requests
3+ from bs4 import BeautifulSoup as bs
4+
5+ def trending ():
6+ url = "https://github.com/trending"
7+ page = requests .get (url )
8+ soup = bs (page .text , 'html.parser' )
9+ data = {}
10+ repo_list = soup .find_all ('article' , attrs = {'class' :'Box-row' })
11+ for repo in repo_list :
12+ full_repo_name = repo .find ('h1' ).find ('a' ).text .strip ().split ('/' )
13+ developer_name = full_repo_name [0 ].strip ()
14+ repo_name = full_repo_name [1 ].strip ()
15+ data [developer_name ] = repo_name
16+ return data
17+
18+ def lambda_handler (event , context ):
19+ data = trending ()
20+ return {
21+ 'statusCode' : 200 ,
22+ 'body' : json .dumps (data )
23+ }
Original file line number Diff line number Diff line change 1+ resource "aws_lambda_function" "trending" {
2+ filename = " function.zip"
3+ function_name = " trending"
4+ role = " cool-stacklifter"
5+ handler = " lambda_function.lambda_handler"
6+ source_code_hash = filebase64sha256 (" function.zip" )
7+ runtime = " python3.9"
8+ }
9+
10+ resource "aws_lambda_function_url" "lambda_function_url" {
11+ function_name = aws_lambda_function. trending . arn
12+ authorization_type = " NONE"
13+ }
14+
15+ output "function_url" {
16+ description = " Function URL."
17+ value = aws_lambda_function_url. lambda_function_url . function_url
18+ }
Original file line number Diff line number Diff line change 1+ requests
2+ bs4
You can’t perform that action at this time.
0 commit comments