├── List-s3-buckets.py ├── List-s3-buckets-2.py ├── ec2-stop-instance.py ├── ec2-start-instance.py ├── ec2-terminate.py ├── delete-s3-bucket.py ├── ec2-create.py ├── create-s3-bucket.py ├── Dynamodb-put-item.py └── DynamoDB-create-table.py /List-s3-buckets.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('s3') 4 | 5 | def lambda_handler(event, context): 6 | response = client.list_buckets() 7 | 8 | print(response) 9 | -------------------------------------------------------------------------------- /List-s3-buckets-2.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('s3') 4 | 5 | def lambda_handler(event, context): 6 | response = client.list_buckets() 7 | bucket = response['Buckets'] 8 | 9 | print(bucket) 10 | -------------------------------------------------------------------------------- /ec2-stop-instance.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('ec2') 4 | 5 | def lambda_handler(event, context): 6 | response = client.stop_instances( 7 | InstanceIds=[ 8 | 'i-03582614278554b9a', 9 | ] 10 | ) 11 | -------------------------------------------------------------------------------- /ec2-start-instance.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('ec2') 4 | 5 | def lambda_handler(event, context): 6 | response = client.start_instances( 7 | InstanceIds=[ 8 | 'i-03582614278554b9a', 9 | ], 10 | ) 11 | -------------------------------------------------------------------------------- /ec2-terminate.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('ec2') 4 | 5 | def lambda_handler(event, context): 6 | response = client.terminate_instances( 7 | InstanceIds=[ 8 | 'i-03582614278554b9a', 9 | ], 10 | ) 11 | -------------------------------------------------------------------------------- /delete-s3-bucket.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('s3') 4 | 5 | def lambda_handler(event, context): 6 | response = client.delete_bucket( 7 | Bucket='lambdapythoncreatebucket24022023', 8 | ) 9 | 10 | print(response) 11 | 12 | -------------------------------------------------------------------------------- /ec2-create.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('ec2') 4 | 5 | def lambda_handler(event, context): 6 | response = client.run_instances( 7 | ImageId='ami-0dfcb1ef8550277af', 8 | InstanceType='t2.micro', 9 | MaxCount=1, 10 | MinCount=1,) 11 | 12 | print(response['Instances'][0]['InstanceId']) 13 | -------------------------------------------------------------------------------- /create-s3-bucket.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('s3') 4 | 5 | def lambda_handler(event, context): 6 | response = client.create_bucket( 7 | Bucket='democreatebucket24022023', 8 | CreateBucketConfiguration={ 9 | 'LocationConstraint': 'us-east-2' # Cannot use -use-east-1 in Lambda 10 | }, 11 | 12 | ) 13 | -------------------------------------------------------------------------------- /Dynamodb-put-item.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('dynamodb') 4 | 5 | def lambda_handler(event, context): 6 | response = client.put_item( 7 | TableName='RetailSales24022023', 8 | Item={ 9 | 'customerID': { 10 | 'S': '001', 11 | }, 12 | 'Product': { 13 | 'S': 'mangoes', 14 | }, 15 | 'Quantity': { 16 | 'N': '100', 17 | }, 18 | 'Address': { 19 | 'S': '115 Queen Elizabeth Road', 20 | }, 21 | }, 22 | ) 23 | 24 | print(response) -------------------------------------------------------------------------------- /DynamoDB-create-table.py: -------------------------------------------------------------------------------- 1 | import json 2 | import boto3 3 | client = boto3.client('dynamodb') 4 | 5 | def lambda_handler(event, context): 6 | response = client.create_table( 7 | AttributeDefinitions=[ 8 | { 9 | 'AttributeName': 'customerID', 10 | 'AttributeType': 'S' 11 | }, 12 | { 13 | 'AttributeName': 'Product', 14 | 'AttributeType': 'S' 15 | }, 16 | ], 17 | TableName='RetailSales24022023', 18 | KeySchema=[ 19 | { 20 | 'AttributeName': 'customerID', 21 | 'KeyType': 'HASH' 22 | }, 23 | { 24 | 'AttributeName': 'Product', 25 | 'KeyType': 'RANGE' 26 | }, 27 | ], 28 | 29 | ProvisionedThroughput={ 30 | 'ReadCapacityUnits': 1, 31 | 'WriteCapacityUnits': 1 32 | }, 33 | ) 34 | print(response) 35 | --------------------------------------------------------------------------------