Skip to content

Commit

Permalink
Sfr 2374 access parameter store (#475)
Browse files Browse the repository at this point in the history
* SSM service and test functionality
  • Loading branch information
Apophenia authored Dec 13, 2024
1 parent 797674b commit 7885f65
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions services/ssm_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import boto3
from typing import Optional

from logger import create_log

logger = create_log(__name__)

ssm_client = boto3.client(
'ssm',
aws_access_key_id=os.environ.get('AWS_ACCESS', None),
aws_secret_access_key=os.environ.get('AWS_SECRET', None),
region_name=os.environ.get('AWS_REGION', None)
)

def get_parameter(parameter_name: str) -> Optional[dict]:
try:
response = ssm_client.get_parameter(
Name=parameter_name,
WithDecryption=True
)
return response

except Exception as err:
logger.exception(f"Parameter store retrieval for {parameter_name} failed")
return None
11 changes: 11 additions & 0 deletions tests/integration/test_ssm_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from load_env import load_env_file

from services.ssm_service import get_parameter

TEST_PARAM = 'arn:aws:ssm:us-east-1:946183545209:parameter/drb/qa/nypl-api/public-key'

def test_get_parameter():
value = get_parameter(TEST_PARAM)

assert value != None

0 comments on commit 7885f65

Please sign in to comment.