0

I'm playing with AWS lambda and I am unable to change the default parameters that are used in the lambda. Is there a workaround for this?

Setup:

Lambda "iAmInvoked" is created by a stack in cloudformation which has default parameter values set (I set these defaults thinking that, these will be used in case invoker doesn't provide values for the parameters required and can be overridden). I'm invoking this iAmInvoked lambda asynchronously using a lambda called "iWillInvoke" and providing the payload which contains new values for parameters to be used by iAmInvoked instead of its defaults.

iWillInvoke code:

import json
import boto3

client = boto3.client('lambda')

def lambda_handler(event, context):
    payloadForLambda = { 'parameter1' : 'abc,def' , 'parameter2' : '123456' , 'parameter3' : '987654' }

    client.invoke(
        FunctionName='arn:aws:lambda:us-west-2:123456789:function:iAmInvoked',
        InvocationType='Event',
        Payload=json.dumps(payloadForLambda)
        )

iAmInvoked Code:

AWSTemplateFormatVersion: 2010-09-09
Description: |
  "Creates required IAM roles to give permission to get and put SSM parameters and creates lambda function that shares the parameter(s)."
Parameters:
  parameter1:
    Type: String
    Default: parameterValueThatShallBeOverridden1
  parameter2:
    Type: String
    Default: parameterValueThatShallBeOverridden2
  parameter3:
    Type: String
    Default: parameterValueThatShallBeOverridden3

Question/Issue:

Doesn't matter what I provide in the payload of iWillInvoke, iAmInvoked is using its default values. Is there a way I can override the defaults?

  • Hello, thanks for checking back. You're right. Issue wasn't with cloudformation template. I was using environmental variables instead of event variables in my Lambda's python code. Fixing this fixed the issue. Thanks! – PraveenBuilds Nov 08 '21 at 17:41

1 Answers1

0

iAmInvoked Code is not your function code nor its parameters. Its CloudFormation template and parameters for the template. Using client.invoke does not affect in any form and shape the CloudFormation template.

To work with CloudFormation in boto3, there is cloudformation SDK.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • You are right, it's part of a cloudformation template which creates a lambda. I didn't add the whole template as it's not relevant for the question. My ask here is, the resulting lambda of the cloudformation template (iAmInvoked) is using the default parameters even though the iWillInvoke is sending different values for parameters in payload. – PraveenBuilds Nov 05 '21 at 02:27
  • @PraveenBuilds As I explained, your lambda invocation has nothing to do with your cloudformation templates. These are two different resources. – Marcin Nov 05 '21 at 02:37