AWS Lambda does not read SSM parameters

0

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

  1. When I run it locally (LocalEntryPoint) and read parameters - it works fine.
  2. When run the Lambda from AWS it cannot read PS and gives me an error
  3. 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?

Oleg
asked 9 months ago501 views
2 Answers
2
Accepted Answer

Make sure your lambda function execution role has sufficient permissions for resources that lambda is going to access.

From the error message, first thing I'd check that your lambda function execution role "pm2supplier-stack-AspNetCoreFunctionRole" has following permissions:

"Effect": "Allow" Action: "ssm:GetParametersByPath" Resource: "arn:aws:ssm:eu-west-2:074xxxxxxxxx:parameter/PM2AWSLambda/"

This is always best practice to follow the least privilege model, but you can first eliminate the error by following policy(giving all GetParameter type access to your lambda execution role ) and then further trim it down to actions, what are actually/exactly required:

"Effect": "Allow" "Action": ["ssm:GetParameter*"] Resource: "arn:aws:ssm:eu-west-2:074xxxxxxxxx:parameter/PM2AWSLambda/"

From the error message, it seems that lambda function execution role requires this permission in one of it's IAM policy but that's not provided anywhere explicitly, which is why this error is coming.

Hope this helps.

Abhishek

profile pictureAWS
EXPERT
answered 9 months ago
profile pictureAWS
EXPERT
iBehr
reviewed 9 months ago
profile picture
EXPERT
reviewed 9 months ago
1

When you create a Lambda function you need to give it an execution role. That role should include, in addition to basic permissions for CloudWatch Logs, also permissions to read from SSM. When you run it locally, it uses different permissions than what you assign to the function. This is why we recommend debugging locally, but running integration tests in the cloud.

profile pictureAWS
EXPERT
Uri
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions