-
Notifications
You must be signed in to change notification settings - Fork 6
/
2_Create_Lambdas.sh
executable file
·68 lines (60 loc) · 3.14 KB
/
2_Create_Lambdas.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Get the ID of the latest created container (must be LocalStack)
containerId=$(docker ps -l -q)
# Inspect the container and get IP address
localIPAddress=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $containerId)
echo "Localstack container IP is $localIPAddress"
awslocal lambda create-function --function-name lambdaUrlValidator \
--code S3Bucket="__local__",S3Key="/Users/anil.ustundag/Github/localstack-demo/lambdas/lambdaUrlValidator" \
--handler index.handler \
--runtime nodejs12.x \
--role whatever;
awslocal lambda create-function --function-name lambdaScraper \
--code S3Bucket="__local__",S3Key="/Users/anil.ustundag/Github/localstack-demo/lambdas/lambdaScraper" \
--handler index.handler \
--runtime nodejs12.x \
--role whatever;
awslocal lambda create-function --function-name lambdaNotifier \
--code S3Bucket="__local__",S3Key="/Users/anil.ustundag/Github/localstack-demo/lambdas/lambdaNotifier" \
--handler index.handler \
--runtime nodejs12.x \
--role whatever;
sleep 1
url="https://www.trendyol.com/apple/iphone-se-2020-64-gb-beyaz-cep-telefonu-apple-turkiye-garantili-p-40776212"
threshold="5000"
awslocal lambda update-function-configuration --function-name lambdaUrlValidator \
--environment "Variables={
accessKeyId=test, secretAccessKey=test, region=eu-central-1,
sqs_queue = http://$localIPAddress:4566/queue/sqs_queue_scrape,
url = $url,
snsTopicArn = arn:aws:sns:eu-central-1:000000000000:sns_topic_price}"
awslocal lambda update-function-configuration --function-name lambdaScraper \
--environment "Variables={
accessKeyId=test, secretAccessKey=test, region=eu-central-1,
sqs_queue = http://$localIPAddress:4566/queue/sqs_queue_notify}"
awslocal lambda update-function-configuration --function-name lambdaNotifier \
--environment "Variables={
accessKeyId=test, secretAccessKey=test, region=eu-central-1,
threshold = $threshold,
snsTopicArn = arn:aws:sns:eu-central-1:000000000000:sns_topic_price}"
sleep 1
awslocal lambda create-event-source-mapping \
--function-name lambdaScraper \
--batch-size 1 \
--event-source-arn arn:aws:sqs:eu-central-1:000000000000:sqs_queue_scrape;
awslocal lambda create-event-source-mapping \
--function-name lambdaNotifier \
--batch-size 1 \
--event-source-arn arn:aws:sqs:eu-central-1:000000000000:sqs_queue_notify;
awslocal sqs purge-queue --queue-url http://localhost:4566/000000000000/sqs_queue_scrape
awslocal sqs purge-queue --queue-url http://localhost:4566/000000000000/sqs_queue_notify
# awslocal lambda invoke \
# --function-name lambdaUrlValidator \
# --invocation-type Event \
# --payload '{ "name": "Bob" }' \
# response.json;
awslocal events put-rule --name twice_a_day --schedule-expression "rate(1 minutes)"
# awslocal events put-rule --name "twice_a_day" --schedule-expression "rate(12 hours)"
# awslocal events put-rule --name "twice_a_day" --schedule-expression "cron(0 0 8,20 * * ?)"
awslocal events put-targets --rule twice_a_day \
--targets "Id"="1","Arn"="arn:aws:lambda:eu-central-1:000000000000:function:lambdaUrlValidator"