0

I’m deploying a stack to 5 account across multiple region, however randomly getting fails on different region/accounts when my lambda is trying to assume a role. Based on my reading I looks like I need to add a delay/ retry to my lambda if it fails. InvalidParameterValueException: The role defined for the function cannot be assumed by Lambda Any idea how I would add that to my code.?

‘’’ ‘use strict';

      const AWS = require('aws-sdk');

      const response = require('./cfn-response');

      const Guardduty = new AWS.Guardduty();



      exports.handler = (event, context, cb) => {



        let region = process.env.AWS_REGION

        let accountId = context.invokedFunctionArn.split(":")[4]

        console.log('Invoke:', JSON.stringify(event));

        const done = (err, data) => {

          if (err) {

            console.log('Error: ', err);

            response.send(event, context, response.FAILED, {}, 'CustomResourcePhysicalID');

          } else {

            console.log('Data: ', data)

            response.send(event, context, response.SUCCESS, {}, 'CustomResourcePhysicalID');

          }

        };



        if (event.RequestType === 'Create' || event.RequestType === 'Update') {

            Guardduty.batchEnableStandards(

                {

                    some API calls



                    ]

                }, done)

            }            

        else if (event.RequestType === 'Delete'){

            Guardduty.batchDisableStandards(

                {

                    some API calls                        

`

                    ]

                }, done)

            }

        else {

          cb(new Error('unsupported RequestType: ', event.RequestType));

        }

      };

  Handler: index.handler

  MemorySize: 128

  Role: !Sub “My_lambda_role”
‘’’
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Mark
  • 33
  • 2
  • 7
  • The code looks like part of a custom resource lambda? – Marcin Jun 02 '20 at 10:34
  • Hi, yes it part of a custom resource lambda, where I’m struggling is in my err statements, what I want to do is try and add a retry if it fails. Thanks M – Mark Jun 02 '20 at 10:41
  • You can't add this in this function. It must be added outside, in a place where you create the function. In the linked SO answer, they use some JavaScript code which calls `createFunction` with a delay to create the functions. – Marcin Jun 02 '20 at 10:45

0 Answers0