|
@ -9,10 +9,10 @@ from botocore.exceptions import ClientError |
|
|
# |
|
|
# |
|
|
################################################################################################ |
|
|
################################################################################################ |
|
|
|
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# a bucket in S3 will be created to store the counter bucket names need to be world-wide unique ;) |
|
|
|
|
|
# Hence we create a bucket name that contains your group number and the current year. |
|
|
|
|
|
# The counter will be stores as key (file) "us-east-1" in the bucket (same name as our default region) |
|
|
|
|
|
# in the bucket and expects a number in it to increase |
|
|
groupNr = 22 |
|
|
groupNr = 22 |
|
|
currentYear = date.today().year |
|
|
currentYear = date.today().year |
|
|
|
|
|
|
|
@ -22,13 +22,21 @@ globallyUniqueS3GroupBucketName = "cloudcomp-counter-" + str(currentYear) + "-gr |
|
|
region = 'us-east-1' |
|
|
region = 'us-east-1' |
|
|
functionName = 'cloudcomp-counter-lambda-demo' |
|
|
functionName = 'cloudcomp-counter-lambda-demo' |
|
|
|
|
|
|
|
|
|
|
|
# The Lambda function will run using privileges of a role, that allows the function to access/create |
|
|
|
|
|
# resources in AWS (in this case read/write to S3). In AWS Academy you need to use the role that |
|
|
|
|
|
# use created for your student account in the lab (see lab readme). |
|
|
# see ARN for AWS Academy LabRole function here: |
|
|
# see ARN for AWS Academy LabRole function here: |
|
|
# https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1#/roles/details/LabRole?section=permissions |
|
|
# https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1#/roles/details/LabRole?section=permissions |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
# roleArn = 'arn:aws:iam::309000625112:role/service-role/cloudcomp-counter-demo-role-6rs7pah3' |
|
|
# roleArn = 'arn:aws:iam::309000625112:role/service-role/cloudcomp-counter-demo-role-6rs7pah3' |
|
|
# roleArn = 'arn:aws:iam::919927306708:role/cloudcomp-s3-access' |
|
|
# roleArn = 'arn:aws:iam::919927306708:role/cloudcomp-s3-access' |
|
|
# roleArn = 'arn:aws:iam::488766701848:role/LabRole' |
|
|
# roleArn = 'arn:aws:iam::488766701848:role/LabRole' |
|
|
|
|
|
|
|
|
|
|
|
# standard name for role in AWS Academy lab created by vocareum is "LabRole". See README of the |
|
|
|
|
|
# lab. The following code will lookup the AWS Resource Name (ARN) (sort of the ID for this role) |
|
|
|
|
|
# that has the following name: |
|
|
|
|
|
roleName = "LabRole" |
|
|
|
|
|
|
|
|
################################################################################################ |
|
|
################################################################################################ |
|
|
# |
|
|
# |
|
|
# boto3 code |
|
|
# boto3 code |
|
@ -56,7 +64,7 @@ print("Getting AWS Academy LabRole ARN...") |
|
|
print("------------------------------------") |
|
|
print("------------------------------------") |
|
|
response = iamClient.list_roles() |
|
|
response = iamClient.list_roles() |
|
|
for role in response["Roles"]: |
|
|
for role in response["Roles"]: |
|
|
if role["RoleName"] == "LabRole": |
|
|
|
|
|
|
|
|
if role["RoleName"] == roleName: |
|
|
roleArn = role["Arn"] |
|
|
roleArn = role["Arn"] |
|
|
print(roleArn) |
|
|
print(roleArn) |
|
|
|
|
|
|
|
@ -136,18 +144,12 @@ print("Lambda Function and S3 Bucket to store the counter are available. Sadly, |
|
|
# that would call our function, as in the provided demo: |
|
|
# that would call our function, as in the provided demo: |
|
|
# |
|
|
# |
|
|
# https://348yxdily0.execute-api.eu-central-1.amazonaws.com/default/cloudcomp-counter-demo |
|
|
# https://348yxdily0.execute-api.eu-central-1.amazonaws.com/default/cloudcomp-counter-demo |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
# print("creating API gateway...") |
|
|
# print("creating API gateway...") |
|
|
# print("------------------------------------") |
|
|
# print("------------------------------------") |
|
|
# |
|
|
# |
|
|
# #apiArn = "" |
|
|
|
|
|
# response = apiClient.create_api( |
|
|
# response = apiClient.create_api( |
|
|
# Name=functionName + '-api', |
|
|
# Name=functionName + '-api', |
|
|
# ProtocolType='HTTP', |
|
|
# ProtocolType='HTTP', |
|
|
# Target=lambdaFunctionARN |
|
|
# Target=lambdaFunctionARN |
|
|
# ) |
|
|
# ) |
|
|
# #apiArn=response[''] |
|
|
|
|
|
# |
|
|
|
|
|
# #response = lClient.create_event_source_mapping( |
|
|
|
|
|
# # EventSourceArn=apiArn, |
|
|
|
|
|
# #) |
|
|
|