Skip to content

Commit

Permalink
Return back dynamodb
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackmorse committed Jul 11, 2024
1 parent c334589 commit 7adebd9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 137 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation("org.apache.tinkerpop:tinkergraph-gremlin:3.6.0")
implementation("org.apache.tinkerpop:gremlin-driver:3.6.0")

implementation("com.typesafe.akka:akka-persistence-dynamodb_2.13:1.2.0-RC2" )

implementation("com.github.dnvriend:akka-persistence-jdbc_2.13:3.5.3")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ fun main() {
botApi.registerBot(englishBot)
}.start()
} catch (e: Exception) {
println(e)
e.printStackTrace()
}
}
32 changes: 28 additions & 4 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,34 @@ akka {
; log-config-on-start = on
}
### leveldb journal and snapshots config
akka.persistence.journal.plugin = "akka.persistence.journal.leveldb"
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
akka.persistence.journal.leveldb.dir = ${?JOURNAL_DIR}
akka.persistence.snapshot-store.local.dir = ${?SNAPSHOT_DIR}
; akka.persistence.journal.plugin = "akka.persistence.journal.leveldb"
; akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
; akka.persistence.journal.leveldb.dir = ${?JOURNAL_DIR}
; akka.persistence.snapshot-store.local.dir = ${?SNAPSHOT_DIR}


akka.persistence.journal.plugin = "my-dynamodb-journal"

my-dynamodb-journal = ${dynamodb-journal} # include the default settings
my-dynamodb-journal { # and add some overrides
journal-table = "englishbot_journal"
journal-name = "akka-persistence_"
aws-access-key-id = ${?AWS_ACCESS_KEY_ID}
aws-secret-access-key = ${?AWS_SECRET_ACCESS_KEY}
endpoint = "https://dynamodb.us-east-1.amazonaws.com"
}

akka.persistence.snapshot-store.plugin = "my-dynamodb-snapshot-store"

my-dynamodb-snapshot-store = ${dynamodb-snapshot-store} # include the default settings
my-dynamodb-snapshot-store {
snapshot-table = "englishbot_snapshots"
journal-name = "akka-persistence_"

aws-access-key-id = ${?AWS_ACCESS_KEY_ID}
aws-secret-access-key = ${?AWS_SECRET_ACCESS_KEY}
endpoint = "https://dynamodb.us-east-1.amazonaws.com"
}


akka {
Expand Down
133 changes: 1 addition & 132 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
version = "~> 5.0"
}
}
}
Expand All @@ -12,26 +12,6 @@ provider "aws" {
shared_credentials_files = ["~/.aws/credentials"]
}

variable "key_name" {
type = string
description = "Name of aws key_pair to assign to EC2"
}

variable "bot_credentials" {
type = string
}

variable "bot_name" {
type = string
}

variable "access_key_id" {
type = string
}

variable "secret_access_key" {
type = string
}

variable "journal_table_name" {
type = string
Expand All @@ -43,93 +23,6 @@ variable "snapshots_table_name" {
default = "englishbot_snapshots"
}

resource "aws_default_vpc" "default" {
}

resource "aws_security_group" "englishbot_sg" {
name = "englishbot_security_group"
description = "English Bot Security group"
vpc_id = aws_default_vpc.default.id

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}

data "aws_ami" "amazon_linux_instance" {
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-kernel-*-hvm-*-x86_64-*"]
}
}

resource "aws_iam_role" "role" {
name = "s3_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}]
})
}

resource "aws_iam_policy" "bot_server_policy" {
name = "bot_server_role"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow"
Resource = "*"
Action = [
"s3:*",
"s3-object-lambda:*"
]
}
]
})
}

resource "aws_iam_role_policy_attachment" "attachment" {
role = aws_iam_role.role.name
policy_arn = aws_iam_policy.bot_server_policy.arn
}

resource "aws_iam_instance_profile" "telegram_bot_profile" {
name = "telegram_bot_profile"
role = aws_iam_role.role.name
}

resource "aws_dynamodb_table" "journal_table" {
name =var.journal_table_name
Expand Down Expand Up @@ -175,27 +68,3 @@ resource "aws_dynamodb_table" "snapshots_table" {
range_key = "ts"
}
}

resource "aws_instance" "telegram_bot" {
ami = data.aws_ami.amazon_linux_instance.id
instance_type = "t2.micro"
security_groups = [aws_security_group.englishbot_sg.name]
iam_instance_profile = aws_iam_instance_profile.telegram_bot_profile.name
key_name = var.key_name

user_data = templatefile("${path.module}/init_server.sh.tpl", {
bot_credentials = var.bot_credentials,
bot_name = var.bot_name
dynamodb_url = "https://dynamodb.us-east-1.amazonaws.com"
access_key_id = var.access_key_id
secret_access_key = var.secret_access_key
journal_table_name = var.journal_table_name
snapshots_table_name = var.snapshots_table_name
}

)

tags = {
Name = "EnglishBotServerTerraform"
}
}

0 comments on commit 7adebd9

Please sign in to comment.