amazon-web-servicesaws-lambdaaws-parameter-store

AWS: Lambda cannot read AWS PS parameters


I have AWS Lambda NET6 function and AWS PS parameters: RDS Connection string Swagger enabled Cognito Authority

When I run it locally (LocalEntryPoint) and read parameters - it works fine. When run the Lambda from AWS it cannot read PS and gives me an error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementException: User: arn:aws:sts::074xxxxxxx:assumed-role/pm2supplier-stack-AspNetCoreFunctionRole-13TO039VZBQ7Y/pm2suppliers is not authorized to perform: ssm:GetParametersByPath on resource: arn:aws:ssm:eu-west-2:074xxxxxxxxx:parameter/PM2AWSLambda/ because no identity-based policy allows the ssm:GetParametersByPath action

How to fix it?


Solution

  • You need to add permission to the Lambda execution role to allow making read calls to the SSM service.

    1. In the AWS Management Console, go to IAM > Roles > Select your role > In the navigation pane, choose Roles > In the list, choose the name of your AWS lambda role OR To view the function's execution role, Open the Functions page of the Lambda console > Choose the name of a function > Choose Configuration Tab, and then choose Permissions > Here you can find the IAM link for your lambda Execution role and also Under Resource summary, you can review the services and resources that the function can access.
    2. Now Choose the Permissions tab in the IAM management console.
    3. Choose Add permissions > Attach policies and then search for AmazonSSMReadOnlyAccess managed policy and checkbox and add it. enter image description here

    Hope this helps.