Skip to content

Instantly share code, notes, and snippets.

@brevityinmotion
Created July 28, 2021 03:50
Show Gist options
  • Save brevityinmotion/d5871e3a4933ccf39a525063134ac1f3 to your computer and use it in GitHub Desktop.
Save brevityinmotion/d5871e3a4933ccf39a525063134ac1f3 to your computer and use it in GitHub Desktop.
Example AWS DynamoDB program loads.
import boto3
import botocore
from botocore.exceptions import ClientError
from dynamodb_json import json_util as dynjson
def create_program(programName):
try:
program = {
'ProgramName': programName
}
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('bugbounty')
table.put_item(
Item=program,
ConditionExpression='attribute_not_exists(ProgramName)'
)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
return 'Program already exists.'
else:
return 'An error occurred adding the program.'
return 'Program successfully added.'
def get_program(programName):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('bugbounty')
resp = table.get_item(
Key={
'ProgramName' : programName,
}
)
if 'Item' in resp:
print(resp['Item'])
def update_program_scopein(programName,scopeIn):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('bugbounty')
table.update_item(
Key={
'ProgramName' : programName,
},
UpdateExpression="set ScopeIn = :g",
ExpressionAttributeValues={
':g': scopeIn
},
ReturnValues="UPDATED_NEW"
)
return 'Scope in successfully added.'
def update_program_scopeout(programName,scopeOut):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('bugbounty')
table.update_item(
Key={
'ProgramName' : programName,
},
UpdateExpression="set ScopeOut = :g",
ExpressionAttributeValues={
':g': scopeOut
},
ReturnValues="UPDATED_NEW"
)
return 'Scope out successfully added.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment