Ends in
00
days
00
hrs
00
mins
00
secs
ENROLL NOW

🎁 Get 20% Off - Christmas Big Sale on All Practice Exams, Video Courses, and eBooks!

Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

Home » AWS » Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

Last updated on March 27, 2023

In today’s world, serverless computing is gaining popularity as it offers technologies for running code, managing data, and integrating applications, all without managing servers. It eliminates the infrastructure management tasks so developers can focus on application development.

One of the requirements of serverless development is storage for configuration data management and secrets management. Developers need to store data such as passwords, database strings, etc., at some point.

Luckily, Parameter Store, a capability of AWS Systems Manager, provides secure, hierarchical storage for configuration data management and secrets management that works well in serverless development. Developers can store values as plain text or encrypted data and can store different logins and reference streams.

For this article, we will demonstrate how Parameter Store can be used for serverless development as it integrates well with Lambda functions.

We will create a simple Lambda function that retrieves values from Parameter Store.

Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

Let’s start.

Step 1. Creating the IAM Role for the Lambda function

  • In the AWS Management Console, go to IAM > Roles > Create role
    Under the Trusted entity type, choose AWS service
    Use case > Lambda
    Click Next

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda
  • On the next page, search for AmazonSSMReadOnlyAccess managed policy
    Click the checkbox next to it
    Choose Next

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda
  • Enter a Role name
    For this example, let’s name it lambda-ssm-read-only

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

    Scroll down and click Create role

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda
  • This will create the IAM Role that the Lambda function will use

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

 

Step 2. Creating Parameters in the Parameter Store to be read by the Lambda function

Tutorials dojo strip
  • Go to the AWS Systems Manager > Parameter Store
    Click Create parameter

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Let’s first create a plain text parameter
    Enter Name, for this example /tutorials-dojo/string/parameter
    Under Type, choose String
    Data type > text
    Enter a Value that you want to be retrieved by the Lambda function
    When done, click Create parameter

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • This will create the parameter.
    Let’s make another one
    This time let’s do a parameter with an encrypted value
    Click Create parameter

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Enter Name
    For this example,/tutorials-dojo/secure-string/parameter
    In Type, choose SecureString
    Enter a Value
    When complete, click Create parameter

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • The two types of parameters are ready to be retrieved by the Lambda function

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

 

Step 3. Creating the Lambda function

  • Go to the Lambda dashboard
    Click Create a function

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Choose Author from scratch
    Under Basic information, enter a Function name
    For this example getValuesFromSSM
    In the Runtime, choose Python 3.9

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Expand the Change default execution role
    Choose Existing role
    In the drop-down list, choose the IAM Role we created in Step 1
    For this example lambda-ssm-read-only
    Click Create function

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • This will create the Lambda function

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Scroll down, then click the Configuration tab
    Choose Environment variables
    Let’s create two that will serve as the placeholder for the Parameters in Parameter Store
    Click Edit

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Click Add environment variable
    In the Key, enter a value
    For this example, PLAIN_TEXT and ENCRYPTED
    Under PLAIN_TEXT, enter the name of the SSM parameter that has a String type
    (for this example: /tutorials-dojo/string/parameter)
    In ENCRYPTED, enter the name of the SSM parameter that has a SecureString type
    (for this example: /tutorials-dojo/secure-string/parameter)
    Click Save when done

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • In the Code tab, paste the script that will allow the Lambda function to retrieve the SSM Parameter values
    and print it

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

  • Now let’s create a test event for the function
    Click Test > Configure test event

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Enter an Event name
    For this example TestEvent
    Leave defaults

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

    Scroll down and click Save

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda
  • Now click Deploy to save the code changes

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Click Test to see if the Lambda function retrieves the SSM parameter values

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • This will run the function, and a new tab will pop
    Check the Execution result
    Under the Function Logs, we can see the values of the SSM Parameters are both printed successfully

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Now let’s try to change the value of one SSM parameter
    Go to the AWS Systems Manager > Parameter Store
    For this example, let’s edit the value of /tutorials-dojo/string/parameter
    Modify the value and click Save changes when done

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

     

  • Now let’s try to run the Lambda function again
    As you can see, the new value of the String type parameter reflected on the Lambda function
    This proves that the Lambda function is working and is retrieving the SSM parameter values successfully

    Retrieving Parameter Values from SSM Parameter Store through AWS Lambda

 

Storing values in AWS Systems Manager Parameter Store is one of the popular ways if you want a dynamic way to store values based on the environment and is a centralized way to manage configuration data. It offers the following benefits:

  • Use a secure, scalable, hosted secrets management service with no servers to manage.

  • Improve your security posture by separating your data from your code.

  • Store configuration data and encrypted strings in hierarchies and track versions.

  • Control and audit access at granular levels.

  • Store parameters reliably because Parameter Store is hosted in multiple Availability Zones in an AWS Region.

 

Get 20% Off – Christmas Big Sale on All Practice Exams, Video Courses, and eBooks!

Tutorials Dojo portal

Learn AWS with our PlayCloud Hands-On Labs

Tutorials Dojo Exam Study Guide eBooks

tutorials dojo study guide eBook

FREE AWS Exam Readiness Digital Courses

FREE AWS, Azure, GCP Practice Test Samplers

Subscribe to our YouTube Channel

Tutorials Dojo YouTube Channel

Follow Us On Linkedin

Recent Posts

Written by: Amiel Palacol

Amiel is a Senior DevOps Engineer based in the Philippines. He has solid hands-on experience in Amazon Web Services (AWS) and loves broadening his technical horizons in the cloud. Currently holds 6 AWS Certifications and outside tech, he loves coffee, games and music.

AWS, Azure, and GCP Certifications are consistently among the top-paying IT certifications in the world, considering that most companies have now shifted to the cloud. Earn over $150,000 per year with an AWS, Azure, or GCP certification!

Follow us on LinkedIn, YouTube, Facebook, or join our Slack study group. More importantly, answer as many practice exams as you can to help increase your chances of passing your certification exams on your first try!

View Our AWS, Azure, and GCP Exam Reviewers Check out our FREE courses

Our Community

~98%
passing rate
Around 95-98% of our students pass the AWS Certification exams after training with our courses.
200k+
students
Over 200k enrollees choose Tutorials Dojo in preparing for their AWS Certification exams.
~4.8
ratings
Our courses are highly rated by our enrollees from all over the world.

What our students say about us?