How to download a file from s3 using an EC2 instance? - amazon-web-services

I have an AMI image in which will be used for autoscaling, every EC2 instance that initiated from the AMI image,suppose to download some files from a s3 bucket, (They are all in the same VPC) the s3 suppose to be private(Not open to public).
How does this can be done?

There are lots of ways. You could use the AWS CLI (S3 Command) or you could use the SDK for the language of your choice. You will also probably want to use IAM to establish the credentials for accessing the resources. The CLI is probably the quickest way to get up and running.

Related

Upload files to Amazon EC2 in a private network from Github Actions

As part of our workflow, we want to upload files to our Amazon EC2 instance automatically.
It's currently only allowing whitelisted IP ranges to connect over SSH. And since we are running Github actions, it seems odd to white list roughly 1500 IP ranges.
Does anyone have an intelligent solution for this?
SCP and/or rsync don't matter for us.
It's merely getting access that I need help with.
I have access to the ssh key, and I can get a hold of an admin to get temporary access to the AWS Console should I need it.
Since the EC2 instance is in a private network, the hurdles to get Github Actions ssh access to it are many.
I would work with a decoupled architecture. Have the GitHub action upload the files to S3.
Then
Lambda can load the file onto the ec2 instance - S3 trigger for Lambda
OR
Have a process running on the ec2 instance poll for new events on the s3 bucket per SNS - S3 polling

Upload files to S3 during deploy

I want to create a bucket during the deployment process, but when I do this, a problem with assets appears, "must have values". So I decide to create a different stack to only upload files and other stack to deploy a EC2 instance. So, when I use this approach, the EC2.UserData didn't find the files on S3 to download them. I need this file to configure my instance. I could create the S3 manually before to deploy the EC2, but I want do automatize this process. How I could do this?
You need to configure S3 access at the machine where you wish to automate the process.
Use AWS CLI tools and run aws configure on your server and define the credentials.
OR
If it is an EC2 instance then create IAM role with S3 write
permissions and attach to this EC2.
You can do the following:
Create 2 separate stacks (we'll refer to them as s3Stack and ec2Stack)
Add ec2Stack.addDependency(s3Stack) where you create these stacks
In the s3 stack, create the bucket and upload the assets using aws-s3-deployment
Give permissions to the ec2 instance to get necessary files from the previously created bucket.
This will ensure you can deploy everything with just one command cdk deploy ec2Stack. It will check if the s3Stack needs to be created/updated first and only when those updates are done, your ec2Stack will be deployed.

How to find out the S3 link of an AMI

I have created an AWS AMI that I want to download to my local machine. I understand that AMIs are stored in S3, and that I can use the ec2-download-bundle command from the AMI cli to download it, but I want to know how to find out which S3 bucket my AMI is in.
Any suggestions?
The AMI's are stored in your account and you pay AMI's storage cost but they aren't really stored in any of your account's s3 bucket. so you can't have specific s3 location to findout these AMI's.

Setting up AWS for data processing S3 or EBS?

Hey there I am new to AWS and trying to piece together the best way to do this.
I have thousands of photos I'd like to upload and process on AWS. The software is Agisoft Photoscan and is run in stages. So for the first stage i'd like to use an instance that is geared towards CPU/Memory usage and the second stage geared towards GPU/Memory.
What is the best way to do this? Do I create a new volume for each project in EC2 and attach that volume to each instance when I need to? I see people saying to use S3, do I just create a bucket for each project and then attach the bucket to my instances?
Sorry for the basic questions, the more I read the more questions I seem to have,
I'd recommend starting with s3 and seeing if it works - will be cheaper and easier to setup. Switch to EBS volumes if you need to, but I doubt you will need to.
You could create a bucket for each project, or you could just create a bucket a segregate the images based on the file-name prefix (i.e. project1-image001.jpg).
You don't 'attach' buckets to EC2, but you should assign an IAM role to the instances as you create them, and then you can grant that IAM role permissions to access the S3 bucket(s) of your choice.
Since you don't have a lot of AWS experience, keep things simple, and using S3 is about as simple as it gets.
You can go with AWS S3 to upload photos. AWS S3 is similar like Google Drive.
If you want to use AWS EBS volumes instead of S3. The problem you may face is,
EBS volumes is accessible within availability zone but not within region also means you have to create snapshots to transfer another availability zone. But S3 is global.
EBS volumes are not designed for storing multimedia files. It is like hard drive. Once you launch an EC2 instance need to attach EBS volumes.
As per best practice, you use AWS S3.
Based on your case view, you can create bucket for each project or you can use single bucket with multiple folders to identify the projects.
Create an AWS IAM role with S3 access permission and attach it to EC2 instance. No need of using AWS Credentials in the project. EC2 instance will use role to access S3 and role doesn't have permanent credentials, it will keep rotating it.

How to store AMI file to S3 bucket?

I am having an Ubuntu ec2 instance at AWS. I took AMI for the instance.
I want to store the AMI to S3 bucket. Is there any way? Also is there anyway to export AMI from S3 bucket?
Update: This feature is now available
From Store and restore an AMI using S3 - Amazon Elastic Compute Cloud:
You can store an Amazon Machine Image (AMI) in an Amazon S3 bucket, copy the AMI to another S3 bucket, and then restore it from the S3 bucket. By storing and restoring an AMI using S3 buckets, you can copy AMIs from one AWS partition to another, for example, from the main commercial partition to the AWS GovCloud (US) partition. You can also make archival copies of AMIs by storing them in an S3 bucket.
--- Old Answer ---
It is not possible to export an AMI.
An Amazon Machine Image (AMI) is a copy of an Elastic Block Store (EBS) volume. The AMI is stored in Amazon S3, but it is not accessible via the S3 service. Think of it as being stored in AWS's own S3 bucket, rather than yours.
If you wish to export a disk image, use a standard disk utility to copy the disk to ISO format, which can then be copied and mounted on other VMs.
Thank you John.
Hi Guys, I had chat with AWS support also. For your reference ,
10:15:45 AM Myself: Well i have some doubts. I will ask and just clear in me on that.
10:15:49 AM AWS support: Sure
10:15:59 AM AWS support: I'll be happy to do so
10:16:25 AM Myself: Is there any option to sore AMI in S3 bucket.
10:16:46 AM AWS support: No, this is not possible
10:17:05 AM AWS support: AMI data is a simple configuration file
10:17:11 AM AWS support: This is backed by S3
10:17:18 AM AWS support: But not stored in an S3 bucket
10:17:27 AM AWS support: The exact same is true for Snapshots
10:17:45 AM AWS support: It is stored and backed by S3- but not something that can be placed in one of your buckets
10:17:59 AM Myself: is it possible to view that in s3?
10:18:51 AM AWS support: No, this is not something that is visible in S3, I am sorry to say
10:19:57 AM Myself: OK. I need to download the AMI . what can i do?
10:20:19 AM AWS support: AMI data is not something that is downloadable
10:20:35 AM AWS support: Are you seeking to Download your whole instance?
10:20:46 AM AWS support: Or download a complete volume?
10:21:07 AM AWS support: If you originally imported your instance from a VM, you can Export the VM 10:21:29 AM AWS support: But its an EC2 instance that was created in EC2, you can not- I am really sorry to say
10:22:02 AM Myself: Okay fine.
I ran into the same problem and to my delight, AWS has since innovated something about this.
You can store and restore your AMI in S3 now.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ami-store-restore.html#store-ami
--
UPDATE:
the version of AWS CLI is matter