Fixed process of updating app on running instances
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m29s
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m29s
This commit is contained in:
@@ -57,7 +57,8 @@ jobs:
|
|||||||
- name: Update application on instance
|
- name: Update application on instance
|
||||||
run: |
|
run: |
|
||||||
INSTANCE_IDS=$(aws ec2 describe-instances \
|
INSTANCE_IDS=$(aws ec2 describe-instances \
|
||||||
--filters "Name=tag:Name,Values=IptvUpdater/IptvUpdaterInstance" \
|
--region us-east-2 \
|
||||||
|
--filters "Name=tag:Name,Values=IptvUpdaterStack/IptvUpdaterInstance" \
|
||||||
"Name=instance-state-name,Values=running" \
|
"Name=instance-state-name,Values=running" \
|
||||||
--query "Reservations[].Instances[].InstanceId" \
|
--query "Reservations[].Instances[].InstanceId" \
|
||||||
--output text)
|
--output text)
|
||||||
|
|||||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -25,6 +25,8 @@
|
|||||||
"pycache",
|
"pycache",
|
||||||
"pyjwt",
|
"pyjwt",
|
||||||
"pytest",
|
"pytest",
|
||||||
|
"PYTHONDONTWRITEBYTECODE",
|
||||||
|
"PYTHONUNBUFFERED",
|
||||||
"reloadcmd",
|
"reloadcmd",
|
||||||
"roomodes",
|
"roomodes",
|
||||||
"ruru",
|
"ruru",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import boto3
|
import boto3
|
||||||
|
from .constants import AWS_REGION
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
@@ -7,8 +8,14 @@ from functools import lru_cache
|
|||||||
|
|
||||||
@lru_cache(maxsize=1)
|
@lru_cache(maxsize=1)
|
||||||
def get_db_credentials():
|
def get_db_credentials():
|
||||||
"""Fetch and cache DB credentials from SSM Parameter Store"""
|
"""Fetch and cache DB credentials from environment or SSM Parameter Store"""
|
||||||
ssm = boto3.client('ssm')
|
if os.getenv("MOCK_AUTH", "").lower() == "true":
|
||||||
|
return (
|
||||||
|
f"postgresql://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}"
|
||||||
|
f"@{os.getenv('DB_HOST')}/{os.getenv('DB_NAME')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
ssm = boto3.client('ssm', region_name=AWS_REGION)
|
||||||
try:
|
try:
|
||||||
host = ssm.get_parameter(Name='/iptv-updater/DB_HOST', WithDecryption=True)['Parameter']['Value']
|
host = ssm.get_parameter(Name='/iptv-updater/DB_HOST', WithDecryption=True)['Parameter']['Value']
|
||||||
user = ssm.get_parameter(Name='/iptv-updater/DB_USER', WithDecryption=True)['Parameter']['Value']
|
user = ssm.get_parameter(Name='/iptv-updater/DB_USER', WithDecryption=True)['Parameter']['Value']
|
||||||
|
|||||||
@@ -86,6 +86,12 @@ class IptvUpdaterStack(Stack):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add EC2 describe permissions
|
||||||
|
role.add_to_policy(iam.PolicyStatement(
|
||||||
|
actions=["ec2:DescribeInstances"],
|
||||||
|
resources=["*"]
|
||||||
|
))
|
||||||
|
|
||||||
# Add Cognito permissions to instance role
|
# Add Cognito permissions to instance role
|
||||||
role.add_managed_policy(
|
role.add_managed_policy(
|
||||||
iam.ManagedPolicy.from_aws_managed_policy_name(
|
iam.ManagedPolicy.from_aws_managed_policy_name(
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ cdk deploy --app="python3 ${PWD}/app.py"
|
|||||||
|
|
||||||
# Update application on running instances
|
# Update application on running instances
|
||||||
INSTANCE_IDS=$(aws ec2 describe-instances \
|
INSTANCE_IDS=$(aws ec2 describe-instances \
|
||||||
--filters "Name=tag:Name,Values=IptvUpdater/IptvUpdaterInstance" \
|
--region us-east-2 \
|
||||||
|
--filters "Name=tag:Name,Values=IptvUpdaterStack/IptvUpdaterInstance" \
|
||||||
"Name=instance-state-name,Values=running" \
|
"Name=instance-state-name,Values=running" \
|
||||||
--query "Reservations[].Instances[].InstanceId" \
|
--query "Reservations[].Instances[].InstanceId" \
|
||||||
--output text)
|
--output text)
|
||||||
|
|||||||
Reference in New Issue
Block a user