filmov
tv
How To: Secrets In Secrets Manager Using Lambda (2 Min) | Python | AWS

Показать описание
In this tutorial, you'll learn how to read secrets in Secrets Manager using an AWS Lambda function in Python and IAM permissions.
—
—
Video Transcript:
_
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to learn secrets in Secrets manager from a Lambda function in AWS. Let's start by navigating to the secrets manager then click on store a new Secret for secret type.
I'm going to choose other than entering a key and a corresponding value. Choose an encryption key then hit next and give your secret a name. I'm going to leave all the other settings to default then copy the sample Python code then hit the store.
Next, let's navigate to the Lambda service and create a new function. Give your function a name, select Python for runtime then hit create function scroll down to the code Source section, and paste the sample Python code. Let's move the import statements to the top and add a return statement to the get underscore secret method.
Next, I'm going to replace the default JSON output by getting the underscore secret method. Hit deploy then click test to give your test event a name. Hit save then click on test again to execute your Lambda function.
Looks like our Lambda function doesn't have permission to get the secret value. To fix this, navigate to the configuration tab then click on the execution role name. Here, we need to attach a policy that gives our Lambda function access to get secret value.
Click policies then hit create policy. For service, select Secrets manager, and for actions, choose to get secret value. In the resources section, click on ADD Arn and copy and paste the Arn of your Secret.
Click next, give your policy a name then hit create policy. Click on roles and navigate back to the execution role of our Lambda function. From the add permissions drop-down, choose to attach policies then attach the policy that we just created.
Now, if we navigate back to our Lambda function and hit test again to execute it, we should see our secrete in the output logs. There you have it. Make sure you like, subscribe, and turn on the notification bell.
Until next time.
—
—
Video Transcript:
_
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to learn secrets in Secrets manager from a Lambda function in AWS. Let's start by navigating to the secrets manager then click on store a new Secret for secret type.
I'm going to choose other than entering a key and a corresponding value. Choose an encryption key then hit next and give your secret a name. I'm going to leave all the other settings to default then copy the sample Python code then hit the store.
Next, let's navigate to the Lambda service and create a new function. Give your function a name, select Python for runtime then hit create function scroll down to the code Source section, and paste the sample Python code. Let's move the import statements to the top and add a return statement to the get underscore secret method.
Next, I'm going to replace the default JSON output by getting the underscore secret method. Hit deploy then click test to give your test event a name. Hit save then click on test again to execute your Lambda function.
Looks like our Lambda function doesn't have permission to get the secret value. To fix this, navigate to the configuration tab then click on the execution role name. Here, we need to attach a policy that gives our Lambda function access to get secret value.
Click policies then hit create policy. For service, select Secrets manager, and for actions, choose to get secret value. In the resources section, click on ADD Arn and copy and paste the Arn of your Secret.
Click next, give your policy a name then hit create policy. Click on roles and navigate back to the execution role of our Lambda function. From the add permissions drop-down, choose to attach policies then attach the policy that we just created.
Now, if we navigate back to our Lambda function and hit test again to execute it, we should see our secrete in the output logs. There you have it. Make sure you like, subscribe, and turn on the notification bell.
Until next time.
Комментарии