I am using AWS Lambda in Ireland region to create AMIs on daily basis for my EC2 prod instance. All my servers are in Ireland region except one which is in the London region.
For the Ireland region, I have the python script for taking backups, I just need to add the code in the same lambda for taking backup pf the London instance as well.
Since am new to both lambda and python, I m not getting where to add or what to add here.
Can Anyone help me here to enable backup for the London instance as well?
The current Lambda script is provided below.
# ec2_client = boto3.client('ec2',region_name=globalVars['REGION_NAME'])
ec2_client = boto3.client('ec2')
AWS is (mostly) region-based. This means that if you wish to communicate with a particular AWS service (eg Amazon EC2) in a particular region, then you must make an API call to that region. It can be done by specifying region_name
when creating the client:
ec2_client = boto3.client('ec2',region_name='ap-southeast-2')
Thereafter, any actions performed on that ec2_client
will be sent to the region that was specified.
For more examples, see: Python boto3- How to work on cross region
If you wish to make calls to multiple regions, you will need to loop through each region and create a boto.client()
for each region in turn.
There are a few exceptions to this requirement for 'global' services: IAM, Route 53 and CloudFront. They replicate configurations between regions, so you can connect to just one region (typically us-east-1
) to configure those services globally.