Skip to content

Instantly share code, notes, and snippets.

View cromyhector's full-sized avatar

Rome Hector cromyhector

View GitHub Profile
import json
import boto3
ec2 = boto3.resource('ec2', region_name='us-east-1')
def lambda_handler(event, context):
instances = ec2.instances.filter(Filters=[
{
'Name': 'instance-state-name',
'Values': ['running']
},
{
import json
import boto3
ec2 = boto3.resource('ec2', region_name='us-east-1')
def lambda_handler(event, context):
instances = ec2.instances.filter(Filters=[
{
'Name': 'instance-state-name',
'Values': ['stopped']
},
{
import boto3
import json
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('LUDreamCar')
with open("dreamcardata.json") as json_file:
dreamcardata = json.load(json_file)
for dreamcar in dreamcardata:
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.create_table(
TableName='LUDreamCar',
KeySchema=[
{
'AttributeName': 'brand',
'KeyType': 'HASH' #Partition key
### dynamodb/variables.tf
variable "aws_region" {
description = "The region where the instance will be deployed to"
type = string
default = "us-east-1"
}
variable "table_name" {
description = "Dynamodb table name"
### --- dynamodb/resources.tf ---
resource "aws_dynamodb_table" "sneakers_table" {
name = var.table_name
read_capacity = 20
write_capacity = 20
hash_key = "BrandName"
range_key = "ModelNumber"
attribute {
### --- dynamodb/providers.tf ---
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
### --- week8.5 root/dynamo.tf ---
module "dynamodb_table" {
source = "./dynamodb"
}
module "instance" {
source = "./ec2"
}
### --- ec2/variables.tf ---
variable "region" {
description = "The region where the instance will be deployed to"
type = string
default = "us-east-1"
}
variable "ami" {
description = "AMI ID"