Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AmazonSimpleSystemsManagementClient GetParameters fails

I have a Lambda in C# and I'm trying to access parameters stored in the ECQ Parameter Store. The parameters are stored as a String Value.

My Lambda is configured to use an existing role. In IAM, I've assigned the following policies to the role:

  • AmazonRedshiftReadOnlyAccess
  • AmazonKinesisReadOnlyAccess
  • AmazonVPCFullAccess
  • AWSLambdaExecute
  • AmazonSSMReadOnlyAccess
  • AWSLambdaVPCAccessExecutionRole

The Lambda runs inside of our VPC and if the parameter value is hard-coded it executes successfully.

My code to get the parameter is:

var client = new AmazonSimpleSystemsManagementClient(RegionEndpoint.APSoutheast2);
var request = new GetParametersRequest
{
   Names = new List<string>{ "ParameterName" }
};
var response = client.GetParametersAsync(request).Result;
var value = response.Parameters.Single().Value;

I have logging before and after the call to GetParametersAsync and it doesn't get to the logging after the call.

What do I need to do to be able to get the parameter value from the Lambda?

like image 806
Anthony Avatar asked Aug 06 '17 23:08

Anthony


Video Answer


2 Answers

The issue was caused by the Lambda running inside of our VPC. Accessing SSM is done via the internet so I had to configure a NAT Gateway to give the Lambda access to the internet.

Once this was done, the Lambda could access the SSM parameters successfully.

like image 72
Anthony Avatar answered Sep 23 '22 19:09

Anthony


You should have something similar to:

public async Task<Response> ProcessS3ImageResizeAsync(SimpleS3Event input)
{
   var response = await client.DoAsyncWork(input);
   return response;
}

In async call the response is not immediate, thus you need to wait before.

More information:

[1] http://docs.aws.amazon.com/lambda/latest/dg/dotnet-programming-model-handler-types.html#dot-net-async

like image 42
mico Avatar answered Sep 20 '22 19:09

mico