-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-resources.sh
executable file
·94 lines (76 loc) · 2.88 KB
/
init-resources.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
apt-get -y install jq
# create bucket
echo "Create Bucket..."
awslocal s3api create-bucket --bucket quotes
# create lambda
echo "Create Quote Lambda..."
awslocal lambda create-function \
--function-name create-quote \
--runtime java17 \
--handler lambda.CreateQuote::handleRequest \
--memory-size 512 \
--zip-file fileb:///etc/localstack/init/ready.d/target/apigw-lambda.jar \
--region us-east-1 \
--role arn:aws:iam::000000000000:role/apigw
echo "Get Quote Lambda..."
awslocal lambda create-function \
--function-name get-quote \
--runtime java17 \
--handler lambda.GetQuote::handleRequest \
--memory-size 512 \
--zip-file fileb:///etc/localstack/init/ready.d/target/apigw-lambda.jar \
--region us-east-1 \
--role arn:aws:iam::000000000000:role/apigw
export REST_API_ID=id12345
# create rest api gateway
echo "Create Rest API..."
awslocal apigateway create-rest-api --name quote-api-gateway --tags '{"_custom_id_":"id12345"}'
# get parent id of resource
echo "Export Parent ID..."
export PARENT_ID=$(awslocal apigateway get-resources --rest-api-id id12345 | jq -r '.items[0].id')
# get resource id
echo "Export Resource ID..."
export RESOURCE_ID=$(awslocal apigateway create-resource --rest-api-id $REST_API_ID --parent-id $PARENT_ID --path-part "quoteApi" | jq -r '.id')
echo "Put GET Method..."
awslocal apigateway put-method \
--rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--request-parameters "method.request.path.quoteApi=true" \
--authorization-type "NONE"
echo "Put POST Method..."
awslocal apigateway put-method \
--rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID \
--http-method POST \
--request-parameters "method.request.path.quoteApi=true" \
--authorization-type "NONE"
echo "Update GET Method..."
awslocal apigateway update-method \
--rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--patch-operations "op=replace,path=/requestParameters/method.request.querystring.param,value=true"
echo "Put POST Method Integration..."
awslocal apigateway put-integration \
--rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID \
--http-method POST \
--type AWS_PROXY \
--integration-http-method POST \
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:create-quote/invocations \
--passthrough-behavior WHEN_NO_MATCH
echo "Put GET Method Integration..."
awslocal apigateway put-integration \
--rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--type AWS_PROXY \
--integration-http-method POST \
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:get-quote/invocations \
--passthrough-behavior WHEN_NO_MATCH
echo "Create DEV Deployment..."
awslocal apigateway create-deployment \
--rest-api-id $REST_API_ID \
--stage-name dev