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”
‘’’