I have written a code that will fetch SSM parameters for me
import boto3
client = boto3.client('ssm')
def lambda_handler(event, context):
return client.get_parameter(Name=event["param"], WithDecryption=True)
if __name__ == '__main__':
print(lambda_handler({"param": "/mypath/password"}, ""))
However, I am not able to write a test case for it I have tried using moto
but for some reason, it still gives me the actual value from the SSM store
import os
import boto3
from moto import mock_ssm
import pytest
from handler import lambda_handler
@pytest.fixture
def aws_credentials():
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"
@mock_ssm
def test_ssm():
ssm = boto3.client('ssm')
ssm.put_parameter(
Name="/mypath/password",
Description="A test parameter",
Value="this is it!",
Type="SecureString"
)
resp = lambda_handler({"param": "/mypath/password"}, "")
assert resp["Parameter"]["Value"] == "this is it!"
Am I missing something overhear, what should I do to make it work, or is there an alternative way to mock SSM in python.