title: access all ec2 cross region via lambda
body: <p>I have lambda function for auto Ami backup is possible to execute lambda across the region for take automatic backup of all my EC2 working on account.</p>
  
  <p>One lambda function execution for all ec2 across region</p>
  
  <pre><code>    var aws = require('aws-sdk');  
  aws.config.region = 'us-east-1','ap-south-1','eu-central-1';  
  var ec2 = new aws.EC2();  
  var now = new Date();  
  date = now.toISOString().substring(0, 10)  
  hours = now.getHours()  
  minutes = now.getMinutes()  
  exports.handler = function(event, context) {  
      var instanceparams = {
          Filters: [{
              Name: 'tag:Backup',
              Values: [
                  'yes'
              ]
          }]
      }
      ec2.describeInstances(instanceparams, function(err, data) {
          if (err) console.log(err, err.stack);
          else {
              for (var i in data.Reservations) {
                  for (var j in data.Reservations[i].Instances) {
                      instanceid = data.Reservations[i].Instances[j].InstanceId;
                      nametag = data.Reservations[i].Instances[j].Tags
                      for (var k in data.Reservations[i].Instances[j].Tags) {
                          if (data.Reservations[i].Instances[j].Tags[k].Key == 'Name') {
                              name = data.Reservations[i].Instances[j].Tags[k].Value;
                          }
                      }
                      console.log("Creating AMIs of the Instance: ", name);
                      var imageparams = {
                          InstanceId: instanceid,
                          Name: name + "_" + date + "_" + hours + "-" + minutes,
                          NoReboot: true
                      }
                      ec2.createImage(imageparams, function(err, data) {
                          if (err) console.log(err, err.stack);
                          else {
                              image = data.ImageId;
                              console.log(image);
                              var tagparams = {
                                  Resources: [image],
                                  Tags: [{
                                      Key: 'DeleteOn',
                                      Value: 'yes'
                                  }]
                              };
                              ec2.createTags(tagparams, function(err, data) {
                                  if (err) console.log(err, err.stack);
                                  else console.log("Tags added to the created AMIs");
                              });
                          }
                      });
                  }
              }
          }
      });
  }
  </code></pre>
  
  <p>where aws.config.region is for region config..it's working for current(in which lambda deploy) region </p>