Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud-computing-msc-ai-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Rieger
cloud-computing-msc-ai-examples
Commits
d796ecc3
Commit
d796ecc3
authored
3 years ago
by
Sebastian Rieger
Browse files
Options
Downloads
Patches
Plain Diff
added API gateway, as in contrast to AWS Academy, localstack allows API gateway creation
parent
2cba78a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
example-projects/counter-demo/aws-lambda-localstack/start.py
+20
-14
20 additions, 14 deletions
example-projects/counter-demo/aws-lambda-localstack/start.py
example-projects/counter-demo/aws-lambda-localstack/stop.py
+14
-2
14 additions, 2 deletions
example-projects/counter-demo/aws-lambda-localstack/stop.py
with
34 additions
and
16 deletions
example-projects/counter-demo/aws-lambda-localstack/start.py
+
20
−
14
View file @
d796ecc3
...
...
@@ -53,6 +53,15 @@ s3Resource = boto3.resource('s3', endpoint_url=endpoint_url)
lClient
=
boto3
.
client
(
'
lambda
'
,
endpoint_url
=
endpoint_url
)
apiClient
=
boto3
.
client
(
"
apigatewayv2
"
,
endpoint_url
=
endpoint_url
)
print
(
"
Deleting old API gateway...
"
)
print
(
"
------------------------------------
"
)
response
=
apiClient
.
get_apis
()
for
api
in
response
[
"
Items
"
]:
if
api
[
"
Name
"
]
==
functionName
+
'
-api
'
:
responseDelete
=
apiClient
.
delete_api
(
ApiId
=
api
[
"
ApiId
"
]
)
print
(
"
Deleting old function...
"
)
print
(
"
------------------------------------
"
)
try
:
...
...
@@ -130,17 +139,14 @@ print("Lambda Function and S3 Bucket to store the counter are available. Sadly,
#
# https://348yxdily0.execute-api.eu-central-1.amazonaws.com/default/cloudcomp-counter-demo
# print("creating API gateway...")
# print("------------------------------------")
#
# #apiArn = ""
# response = apiClient.create_api(
# Name=functionName + '-api',
# ProtocolType='HTTP',
# Target=lambdaFunctionARN
# )
# #apiArn=response['']
#
# #response = lClient.create_event_source_mapping(
# # EventSourceArn=apiArn,
# #)
print
(
"
creating API gateway...
"
)
print
(
"
------------------------------------
"
)
response
=
apiClient
.
create_api
(
Name
=
functionName
+
'
-api
'
,
ProtocolType
=
'
HTTP
'
,
Target
=
lambdaFunctionARN
)
apiArn
=
response
print
(
"
API Endpoint can be reached at: http://
"
+
apiArn
[
"
ApiEndpoint
"
])
This diff is collapsed.
Click to expand it.
example-projects/counter-demo/aws-lambda-localstack/stop.py
+
14
−
2
View file @
d796ecc3
...
...
@@ -7,6 +7,8 @@ import boto3
#
################################################################################################
endpoint_url
=
"
http://localhost.localstack.cloud:4566
"
# you need to create a bucket in S3, here in this demo it is called "cloudcomp-counter", but
# bucket names need to be world wide unique ;) The demo looks for a file that is named
# "us-east-1" (same as our default region) in the bucket and expects a number in it to increase
...
...
@@ -40,9 +42,19 @@ def cleanup_s3_bucket(s3_bucket):
client
=
boto3
.
setup_default_session
(
region_name
=
region
)
s3Client
=
boto3
.
client
(
'
s3
'
)
s3Resource
=
boto3
.
resource
(
'
s3
'
)
lClient
=
boto3
.
client
(
'
lambda
'
)
s3Resource
=
boto3
.
resource
(
'
s3
'
,
endpoint_url
=
endpoint_url
)
lClient
=
boto3
.
client
(
'
lambda
'
,
endpoint_url
=
endpoint_url
)
apiClient
=
boto3
.
client
(
"
apigatewayv2
"
,
endpoint_url
=
endpoint_url
)
print
(
"
Deleting old API gateway...
"
)
print
(
"
------------------------------------
"
)
response
=
apiClient
.
get_apis
()
for
api
in
response
[
"
Items
"
]:
if
api
[
"
Name
"
]
==
functionName
+
'
-api
'
:
responseDelete
=
apiClient
.
delete_api
(
ApiId
=
api
[
"
ApiId
"
]
)
print
(
"
Deleting old function...
"
)
print
(
"
------------------------------------
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment