首页 \ 问答 \ Boto3不会将快照复制到其他区域,其他选项?(Boto3 not copying snapshot to other regions, other options?)

Boto3不会将快照复制到其他区域,其他选项?(Boto3 not copying snapshot to other regions, other options?)

[对AWS很新]

嗨,

我正在尝试将EBS卷快照拷贝跨区域移动。 我一直在尝试使用Boto3来移动快照。 我的目标是每天自动将最新快照从us-east-2区域移动到us-east-1区域。

我在终端中使用了aws configure命令来设置我的安全凭证并将区域设置为us-east-2

我使用熊猫来获取使用此代码的最新快照ID:

import boto3
import pandas as pd
from pandas.io.json.normalize import nested_to_record    
import boto.ec2


    client = boto3.client('ec2')
    aws_api_response = client.describe_snapshots(OwnerIds=['self'])
    flat = nested_to_record(aws_api_response)
    df = pd.DataFrame.from_dict(flat)
    df= df['Snapshots'].apply(pd.Series)
    insert_snap = df.loc[df['StartTime'] == max(df['StartTime']),'SnapshotId']
    insert_snap = insert_snap.reset_index(drop=True)

insert_snap返回一个类似snap-1234ABCD的快照标识

我尝试使用此代码将快照从us-east-2到u s-east-1

client.copy_snapshot(SourceSnapshotId='%s' %insert_snap[0],
                     SourceRegion='us-east-2',
                     DestinationRegion='us-east-1',
                     Description='This is my copied snapshot.')

快照正在使用上述行复制到同一区域。

我也尝试通过终端中的aws configure命令切换区域,在同一区域中复制快照时发生同样的问题。

Boto3中存在一个跳过copy_snapshot()代码中的目标参数的copy_snapshot() 。 在这里找到的信息: https//github.com/boto/boto3/issues/886

我曾尝试将此代码插入到lambda管理器中,但不断收到错误"errorMessage": "Unable to import module 'lambda_function'"

region = 'us-east-2'
ec = boto3.client('ec2',region_name=region)

def lambda_handler(event, context):
    response=ec.copy_snapshot(SourceSnapshotId='snap-xxx',
                     SourceRegion=region,
                     DestinationRegion='us-east-1',
                     Description='copied from Ohio')
    print (response)

我没有选择,我可以做些什么来自动化aws中的快照传输?


[Very new to AWS]

Hi,

I am trying to move my EBS volume snapshot copies across regions. I have been trying to use Boto3 to move the snapshots. My objective is to move the latest snapshot from us-east-2 region to us-east-1 region automatically on a daily basis.

I have used aws configure command in terminal to setup my security credentials and set region to us-east-2.

I am using pandas to acquire the most recent snapshot-id using this code:

import boto3
import pandas as pd
from pandas.io.json.normalize import nested_to_record    
import boto.ec2


    client = boto3.client('ec2')
    aws_api_response = client.describe_snapshots(OwnerIds=['self'])
    flat = nested_to_record(aws_api_response)
    df = pd.DataFrame.from_dict(flat)
    df= df['Snapshots'].apply(pd.Series)
    insert_snap = df.loc[df['StartTime'] == max(df['StartTime']),'SnapshotId']
    insert_snap = insert_snap.reset_index(drop=True)

insert_snap returns a snapshot id something like snap-1234ABCD

I am try to use this code to move the snap shot from us-east-2 to us-east-1:

client.copy_snapshot(SourceSnapshotId='%s' %insert_snap[0],
                     SourceRegion='us-east-2',
                     DestinationRegion='us-east-1',
                     Description='This is my copied snapshot.')

The snapshot is copying in the same region using the above line.

I have also tried switching regions through aws configure command in terminal, with the same issue occurring where snapshot is being copied in the same region.

There is a bug in Boto3 that is skipping the destination parameter in the copy_snapshot() code. Information found here: https://github.com/boto/boto3/issues/886

I have tried inserting this code with into the lambda manager but keep getting error "errorMessage": "Unable to import module 'lambda_function'":

region = 'us-east-2'
ec = boto3.client('ec2',region_name=region)

def lambda_handler(event, context):
    response=ec.copy_snapshot(SourceSnapshotId='snap-xxx',
                     SourceRegion=region,
                     DestinationRegion='us-east-1',
                     Description='copied from Ohio')
    print (response)

I am out of options, what I can do to automate the transfer of snapshots in aws?


原文:https://stackoverflow.com/questions/50414179
更新时间:2022-04-27 19:04

最满意答案

您可以尝试使用Volley或类似的库来完成任务。 使用它比使用旧方法简单得多。 您通常需要重新编写Web服务调用,但我可以保证它不会像您已经完成的那样困难! 这是关于如何使用Volley的教程。 开始使用非常简单。

以下是他们网站上有关如何使用Volley的简单示例。 https://developer.android.com/training/volley/requestqueue.html

RequestQueue mRequestQueue;

// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

String url ="http://www.example.com";

// Formulate the request and handle the response.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Do something with the response
    }
},
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // Handle error
    }
});

// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);

you can try using Volley or similar libraries to get your task done. It's much simpler to use than the old approach. You'll mostly need to re-write the web service calls, but I can guarantee that it won't be as difficult as what you've already done! Here's a tutorial on how to use Volley. It's very easy to get started with.

Following is a simple example as given on their website on how to use Volley. https://developer.android.com/training/volley/requestqueue.html

RequestQueue mRequestQueue;

// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

String url ="http://www.example.com";

// Formulate the request and handle the response.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Do something with the response
    }
},
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // Handle error
    }
});

// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);

相关问答

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)