def create_dynamo_table(self): t = self.template self.dynamoTable = t.add_resource(Table( "moviesDBTable", AttributeDefinitions=[ AttributeDefinition( AttributeName="id", AttributeType="S" ) ], KeySchema=[ KeySchema( AttributeName="id", KeyType="HASH" ) ], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=5, WriteCapacityUnits=5 ), StreamSpecification=StreamSpecification( StreamViewType="NEW_IMAGE" ) )) t.add_output(Output( "TableName", Value=Ref(self.dynamoTable), Description="Table name of my new sample table" )) t.add_output(Output( "StreamArn", Value=GetAtt(self.dynamoTable, "StreamArn") ))
def add_dynamobd_terminate_db(self): self.terminate_dynamodb = self.template.add_resource( Table("terminationDB", TableName="terminateDB", TimeToLiveSpecification=TimeToLiveSpecification( AttributeName="ttl", Enabled=True), AttributeDefinitions=[ AttributeDefinition(AttributeName="termination", AttributeType="S"), ], KeySchema=[ KeySchema(AttributeName="termination", KeyType="HASH") ], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=2, WriteCapacityUnits=1)))
def add_dynamo_db(self): self.dynamo_db = self.template.add_resource(Table( "dynamoDBTable", AttributeDefinitions=[ AttributeDefinition( AttributeName=self.sceptre_user_data["HashKeyElementName"], AttributeType=self.sceptre_user_data["HashKeyElementType"] ) ], KeySchema=[ KeySchema( AttributeName=self.sceptre_user_data["HashKeyElementName"], KeyType="HASH" ) ], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=self.sceptre_user_data["ReadCapacityUnits"], WriteCapacityUnits=self.sceptre_user_data["WriteCapacityUnits"] ) ))
def add_table(self): table_kwargs = {"TableName": Ref(self.table_name)} table_properties = self.sceptre_user_data["TableProperties"] # Parse the provided KeySchema table_kwargs.update({"KeySchema": []}) for schema in table_properties.pop("KeySchema"): key_schema = KeySchema(**self.parse_key_schema(schema)) table_kwargs["KeySchema"].append(key_schema) # Parse the provisioned throughput table_kwargs.update({ "ProvisionedThroughput": ProvisionedThroughput(**table_properties["ProvisionedThroughput"]) }) # Parse attribute definitions if table_properties.get("AttributeDefinitions"): table_kwargs.update({"AttributeDefinitions": []}) for definition in table_properties.pop("AttributeDefinitions"): attribute_kwargs = { "AttributeName": definition.keys()[0], "AttributeType": definition.values()[0] } attribute_definition = AttributeDefinition(**attribute_kwargs) table_kwargs["AttributeDefinitions"].append( attribute_definition) # Parse the stream specification if table_properties.get("StreamSpecification"): table_kwargs.update({ "StreamSpecification": StreamSpecification( **table_properties.pop("StreamSpecification")) }) # Parse the time to live properties # if table_properties.get("TimeToLiveSpecification"): # table_kwargs.update({"TimeToLiveSpecification": TimeToLiveSpecification(**table_properties.pop("TimeToLiveSpecification"))}) # Geez that was a lot of parsing. Y u make so difficult, AWS? # Create the table, finally. dynamo_table = self.template.add_resource( Table("DynamoTable", **table_kwargs)) self.template.add_output(Output("DynamoTable", Value=Ref(dynamo_table)))
def create_dynamo_table(self): t = self.template self.dynamoTable = t.add_resource( Table("sampleDBTable", AttributeDefinitions=[ AttributeDefinition(AttributeName="artist", AttributeType="S"), AttributeDefinition(AttributeName="album", AttributeType="S") ], KeySchema=[ KeySchema(AttributeName="artist", KeyType="HASH"), KeySchema(AttributeName="album", KeyType="RANGE") ], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=5, WriteCapacityUnits=5))) t.add_output( Output("TableName", Value=Ref(self.dynamoTable), Description="Table name of my new sample table"))
def create_stats_table(self, table_name): stats_table = Table( table_name, AttributeDefinitions=[ AttributeDefinition(AttributeName="stat_id", AttributeType="S"), AttributeDefinition(AttributeName="session_id", AttributeType="S"), AttributeDefinition(AttributeName="question_id", AttributeType="S"), AttributeDefinition(AttributeName="no_of_answers", AttributeType="N"), AttributeDefinition(AttributeName="answers", AttributeType="S"), AttributeDefinition(AttributeName="create_date", AttributeType="S") ], KeySchema=[KeySchema(AttributeName="stat_id", KeyType="HASH")], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=Ref(PARAMETER_READ_CAPACITY), WriteCapacityUnits=Ref(PARAMETER_WRITE_CAPACITY))) self.t.add_resource(stats_table)
def create_question_table(self, table_name): question_table = Table( table_name, AttributeDefinitions=[ AttributeDefinition(AttributeName="question_id", AttributeType="S"), AttributeDefinition(AttributeName="question_text", AttributeType="S"), AttributeDefinition(AttributeName="question_image_url", AttributeType="S"), AttributeDefinition(AttributeName="category", AttributeType="S"), AttributeDefinition(AttributeName="answers", AttributeType="S"), AttributeDefinition(AttributeName="create_date", AttributeType="S") ], KeySchema=[KeySchema(AttributeName="question_id", KeyType="HASH")], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=Ref(PARAMETER_READ_CAPACITY), WriteCapacityUnits=Ref(PARAMETER_WRITE_CAPACITY))) self.t.add_resource(question_table)
MinValue="5", MaxValue="10000", ConstraintDescription="should be between 5 and 10000")) writeunits = t.add_parameter( Parameter("WriteCapacityUnits", Description="Provisioned write throughput", Type="Number", Default="10", MinValue="5", MaxValue="10000", ConstraintDescription="should be between 5 and 10000")) myDynamoDB = t.add_resource( Table("myDynamoDBTable", AttributeDefinitions=[ AttributeDefinition(Ref(hashkeyname), Ref(hashkeytype)), ], KeySchema=[Key(Ref(hashkeyname), "HASH")], ProvisionedThroughput=ProvisionedThroughput(Ref(readunits), Ref(writeunits)))) t.add_output( Output( "TableName", Value=Ref(myDynamoDB), Description="Table name of the newly create DynamoDB table", )) print(t.to_json())
readunits = t.add_parameter( Parameter("ReadCapacityUnits", Description="Provisioned read throughput", Type="Number", Default="1", MinValue="1", MaxValue="1", ConstraintDescription="should be between 1 and 5")) writeunits = t.add_parameter( Parameter("WriteCapacityUnits", Description="Provisioned write throughput", Type="Number", Default="1", MinValue="1", MaxValue="1", ConstraintDescription="should be between 1 and 5")) t.add_resource( Table( "LambdaAppDynamoDB", AttributeDefinitions=[ AttributeDefinition(AttributeName=Ref(hashkeyname), AttributeType=Ref(hashkeytype)) ], KeySchema=[KeySchema(AttributeName=Ref(hashkeyname), KeyType="HASH")], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=Ref(readunits), WriteCapacityUnits=Ref(writeunits))))
Parameter( 'FromEmail', ConstraintDescription='Must be an email address', Description= 'Email address that is verified to send outbound SES emails', Type="String", AllowedPattern=r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")) ## DynamoDB table to hold email addresses email_table = t.add_resource( Table("emailListTable", AttributeDefinitions=[ AttributeDefinition(AttributeName="email", AttributeType="S"), ], KeySchema=[KeySchema(AttributeName="email", KeyType="HASH")], ProvisionedThroughput=ProvisionedThroughput(ReadCapacityUnits=5, WriteCapacityUnits=5), TableName=dynamo_table_name)) t.add_output( Output( "emailListTableName", Value=Ref(email_table), Description="Table Name", )) # Policies allow_db_access_policy = t.add_resource( ManagedPolicy( "AllowDynamoEmailList", Description= "IAM Managed Policy to have full access to DynamoDB Email List Table",
def add_dynamodb(template: Template) -> Table: hash_key_name = template.add_parameter( Parameter( "HashKeyElementName", Description="HashType PrimaryKey Name", Type="String", AllowedPattern="[a-zA-Z0-9]*", MinLength="1", MaxLength="2048", Default="date", ConstraintDescription="must contain only alphanumberic characters") ) hash_key_type = template.add_parameter( Parameter("HashKeyElementType", Description="HashType PrimaryKey Type", Type="String", Default="S", AllowedPattern="[S|N]", MinLength="1", MaxLength="10", ConstraintDescription="must be either S or N")) read_units = template.add_parameter( Parameter("ReadCapacityUnits", Description="Provisioned read throughput", Type="Number", Default="5", MinValue="5", MaxValue="10000", ConstraintDescription="should be between 5 and 10000")) write_units = template.add_parameter( Parameter("WriteCapacityUnits", Description="Provisioned write throughput", Type="Number", Default="10", MinValue="5", MaxValue="10000", ConstraintDescription="should be between 5 and 10000")) my_dynamodb = template.add_resource( Table("myDynamoDBTable", AttributeDefinitions=[ AttributeDefinition(AttributeName=Ref(hash_key_name), AttributeType=Ref(hash_key_type)), ], KeySchema=[ KeySchema(AttributeName=Ref(hash_key_name), KeyType="HASH") ], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=Ref(read_units), WriteCapacityUnits=Ref(write_units)))) template.add_output( Output( "TableName", Value=Ref(my_dynamodb), Description="Table name of the newly create DynamoDB table", )) return my_dynamodb
def create_template(): t = Template() t.add_description("The DynamoDB tables stack for CBuildCI.") p_config_table_name = t.add_parameter(Parameter( "ConfigTableName", Type = "String", )) p_locks_table_name = t.add_parameter(Parameter( "LocksTableName", Type = "String", )) p_sessions_table_name = t.add_parameter(Parameter( "SessionsTableName", Type = "String", )) p_executions_table_name = t.add_parameter(Parameter( "ExecutionsTableName", Type = "String", )) p_config_table_rcu = t.add_parameter(Parameter( "ConfigTableRCU", Type = "Number", Default = "5", )) p_config_table_wcu = t.add_parameter(Parameter( "ConfigTableWCU", Type = "Number", Default = "1", )) p_locks_table_rcu = t.add_parameter(Parameter( "LocksTableRCU", Type = "Number", Default = "5", )) p_locks_table_wcu = t.add_parameter(Parameter( "LocksTableWCU", Type = "Number", Default = "2", )) p_sessions_table_rcu = t.add_parameter(Parameter( "SessionsTableRCU", Type = "Number", Default = "5", )) p_sessions_table_wcu = t.add_parameter(Parameter( "SessionsTableWCU", Type = "Number", Default = "2", )) p_executions_table_rcu = t.add_parameter(Parameter( "ExecutionsTableRCU", Type = "Number", Default = "15", )) p_executions_table_wcu = t.add_parameter(Parameter( "ExecutionsTableWCU", Type = "Number", Default = "5", )) p_executions_search_indexes_rcu = t.add_parameter(Parameter( "ExecutionsSearchIndexesRCU", Type = "Number", Default = "5", )) p_executions_search_indexes_wcu = t.add_parameter(Parameter( "ExecutionsSearchIndexesWCU", Type = "Number", Default = "1", )) # Replace with custom tags if desired. tags = build_tags_list(t) t.add_resource(Table( "ConfigDBTable", DeletionPolicy = "Retain", TableName = Ref(p_config_table_name), KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "id", ), ], AttributeDefinitions = [ AttributeDefinition( AttributeName = "id", AttributeType = "S", ), ], ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_config_table_rcu), WriteCapacityUnits = Ref(p_config_table_wcu) ), Tags = tags, )) t.add_resource(Table( "LocksTable", DeletionPolicy = "Retain", TableName = Ref(p_locks_table_name), KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "id", ), ], AttributeDefinitions = [ AttributeDefinition( AttributeName = "id", AttributeType = "S", ), ], ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_locks_table_rcu), WriteCapacityUnits = Ref(p_locks_table_wcu) ), Tags = tags, )) t.add_resource(Table( "SessionsTable", DeletionPolicy = "Retain", TableName = Ref(p_sessions_table_name), KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "id", ), ], AttributeDefinitions = [ AttributeDefinition( AttributeName = "id", AttributeType = "S", ), ], ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_sessions_table_rcu), WriteCapacityUnits = Ref(p_sessions_table_wcu) ), TimeToLiveSpecification = TimeToLiveSpecification( Enabled = True, AttributeName = "ttlTime", ), Tags = tags, )) t.add_resource(Table( "ExecutionsTable", DeletionPolicy = "Retain", TableName = Ref(p_executions_table_name), KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "repoId", ), KeySchema( KeyType = "RANGE", AttributeName = "executionId", ), ], AttributeDefinitions = [ AttributeDefinition( AttributeName = "repoId", AttributeType = "S", ), AttributeDefinition( AttributeName = "executionId", AttributeType = "S", ), AttributeDefinition( AttributeName = "createTime", AttributeType = "S", ), ], ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_executions_table_rcu), WriteCapacityUnits = Ref(p_executions_table_wcu) ), Tags = tags, GlobalSecondaryIndexes = [ GlobalSecondaryIndex( IndexName = "search-repoId-createTime-index", KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "repoId", ), KeySchema( KeyType = "RANGE", AttributeName = "createTime", ), ], Projection = Projection( NonKeyAttributes = [ "repoId", "executionId", "createTime", "updateTime", "status", "conclusion", "conclusionTime", "meta", ], ProjectionType = "INCLUDE", ), ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_executions_search_indexes_rcu), WriteCapacityUnits = Ref(p_executions_search_indexes_wcu), ), ), GlobalSecondaryIndex( IndexName = "search-repoId-executionId-index", KeySchema = [ KeySchema( KeyType = "HASH", AttributeName = "repoId", ), KeySchema( KeyType = "RANGE", AttributeName = "executionId", ), ], Projection = Projection( NonKeyAttributes = [ "repoId", "executionId", "createTime", "updateTime", "status", "conclusion", "conclusionTime", "meta", ], ProjectionType = "INCLUDE", ), ProvisionedThroughput = ProvisionedThroughput( ReadCapacityUnits = Ref(p_executions_search_indexes_rcu), WriteCapacityUnits = Ref(p_executions_search_indexes_wcu), ), ), ], )) return t
# API Gateway ##################################################################################################################### rest_api = t.add_resource( RestApi("api", Name="{}-{}".format(env_l, app_group_l))) ##################################################################################################################### # DynamoDB table ##################################################################################################################### myDynamoDB = t.add_resource( Table("myDynamoDBTable", TableName='counters', AttributeDefinitions=[ AttributeDefinition(AttributeName='website', AttributeType='S') ], KeySchema=[KeySchema(AttributeName='website', KeyType='HASH')], ProvisionedThroughput=ProvisionedThroughput( ReadCapacityUnits=readunits, WriteCapacityUnits=writeunits))) ##################################################################################################################### # Lambda ##################################################################################################################### # Create a Lambda function that will be mapped code = [ "var response = require('cfn-response');", "exports.handler = function(event, context) {", " context.succeed('foobar!');", " return 'foobar!';", "};", ] # Create a role for the lambda function t.add_resource(
Value=GetAtt(queue, "Arn")), ]) # DyanamoDB: NetKAN Status netkan_db = t.add_resource( Table( "NetKANStatus", AttributeDefinitions=[ AttributeDefinition(AttributeName="ModIdentifier", AttributeType="S"), ], KeySchema=[KeySchema(AttributeName="ModIdentifier", KeyType="HASH")], TableName="NetKANStatus", ProvisionedThroughput=ProvisionedThroughput( # The free tier allows for 25 R/W Capacity Units # 5 allocated already for dev testing ReadCapacityUnits=20, WriteCapacityUnits=20))) t.add_output( Output( "TableName", Value=Ref(netkan_db), Description="Table name of the newly create DynamoDB table", )) # Instance Role for Prod Indexing Instance to be able to # access the relevant AWS resources. We can lock it all # down to the container level, but this is unnecessary for # now. netkan_role = t.add_resource(
build_version = t.add_parameter(Parameter("BuildVersion", Type="String")) t.add_description(COMPONENT_NAME + " stacks") companyTable = t.add_resource( Table("Table", AttributeDefinitions=[ AttributeDefinition(AttributeName="uuid", AttributeType="S"), AttributeDefinition(AttributeName="administratorAndName", AttributeType="S") ], KeySchema=[ KeySchema(AttributeName="uuid", KeyType="HASH"), KeySchema(AttributeName="administratorAndName", KeyType="RANGE") ], ProvisionedThroughput=ProvisionedThroughput(ReadCapacityUnits=1, WriteCapacityUnits=1))) companyTableAN = t.add_resource( Table( "TableAN", AttributeDefinitions=[ AttributeDefinition(AttributeName="administratorAndName", AttributeType="S"), AttributeDefinition(AttributeName="uuid", AttributeType="S") ], KeySchema=[ KeySchema(AttributeName="administratorAndName", KeyType="HASH"), KeySchema(AttributeName="uuid", KeyType="RANGE") ], ProvisionedThroughput=ProvisionedThroughput(ReadCapacityUnits=1, WriteCapacityUnits=1),