Using AWS CLI from EC2 instance without internet access - amazon-web-services

Is there a way to use AWS CLI to call different services such as SQS, EC2, SNS from EC2 linux instance?
The EC2 instance from where the AWS CLI command are invoked does not have access to internet. It is in private subnet. It is not using internet gateway or NAT.
Thanks,

Not possible. The CLI has to access the API endpoints for all the services you mentioned. For that the CLI needs internet access. Only service it can access without internet is the internal metadata server.
AWS Regions and Endpoints

VPC endpoints create a private connection between your VPC and an AWS service. However, currently the only supported service is S3 and none of the services listed in your question.
Currently, we support endpoints for connections with Amazon S3 only.
We'll add support for other AWS services later. Endpoints are
supported within the same region only.

Related

Accessing S3 from inside EKS using boto3

I have a Python application deployed on EKS (Elastic Kubernetes Service). This application saves large files inside an S3 bucket using the AWS SDK for Python (boto3). Both the EKS cluster and the S3 bucket are in the same region.
My question is, how is communication between the two services (EKS and S3) handled by default?
Do both services communicate directly and internally through the Amazon network, or do they communicate externally via the Internet?
If they communicate via the internet, is there a step by step guide on how to establish a direct internal connection between both services?
how is communication between the two services (EKS and S3) handled by default?
By default the network topology of your EKS offers route to the public AWS S3 endpoints.
Do both services communicate directly and internally through the Amazon network, or do they communicate externally via the Internet?
Your cluster needs to have network access to the said public AWS S3 endpoints. Example, worker nodes running in public subnet or the use of NAT gateway in private subnet.
...is there a step by step guide on how to establish a direct internal connection between both services?
You create VPC endpoints for S3 in the VPC that your EKS runs to ensure network communication with S3 stay within AWS network. VPC endpoints for S3 support both interface and gateway type. Try this article to learn about the basic of S3 endpoints, you can use the same method to create endpoints in the VPC where your EKS runs. Request to S3 from your pods will then use the endpoint to reach out to S3 within AWS network.
You can add S3 access to your EKS node IAM role, this link shows you how to add ECR registry access to EKS node IAM role, but it is the same for S3.
The other way is to make environment variables available in your container, see this link, though I would recommend the first way.

How do I create an AWS VPC Endpoint for Elasticsearch?

I have a lambda function which must be placed in a VPC because it communicates over a VPC peering connection. I also need it to upload to my Elasticsearch Service domain (not in a VPC because it is publicly accessible). But currently when Lambda tries to talk to ES, it times out.
I ran into this problem with Secrets Manager, so I went into the lambda's VPC, clicked on Endpoints, and created a Secrets Manager endpoint. I would like to do the same with Elasticsearch Service, but it doesn't show up in my list of AWS Services, which is odd because it definitely is an AWS Service.
Any idea how I can add an endpoint for Elasticsearch Service in my VPC so my Lambda function can talk to it? Thanks!
There is no VPC endpoint for ES. The services that support the endpoints are listed here.
Regarding the timeout, you would have to provided detailed description of your VPC setup, subnets, route tables, lambda and explain how did you setup your ES and how do you try to access it from VPC. Its difficult to speculate why it times out without all the details.
But since your ES is public, one possibility could be because lambda in VPC will not be able to connect to it without the use of NAT gateway. By default, lambda in a VPC does not have internet connectivity.

Why do VPC endpoints not support Amazon RDS?

I want to execute AWS CLI commands of RDS not via the internet, but via a VPC network for mainly creating manual snapshots of RDS.
However, VPC endpoints support only RDS Data API according to the following document:
VPC endpoints - Amazon Virtual Private Cloud
Why? I need to execute a command within closed network for security rules.
Just to reiterate you can still connect to your RDS database through the normal private network using whichever library you choose to perform any DDL, DML, DCL and TCL commands. Although in your case you want to create a snapshot which is via the service endpoint.
VPC endpoints are to connect to the service APIs that power AWS (think the interactions you perform in the console, SDK or CLI), at the moment this means for RDS to create, modify or delete resources you need to use the API over the public internet (using HTTPS for encrypted traffic).
VPC endpoints are added over time, just because a specific API is not there now does not mean it will never be there. There is an integration that has to be carried out by the team of that AWS service to allow VPC endpoints to work.

How to allow ecs private application access to internet if using only aws PrivateLink

I have deployed multiple applications(docker containers) by ECS on private subnet. NAT Gateway is used to allow internet access. Due to active deployment, the images download from ECR by nat gateway is costing too much due to their size.
I am planning on using AWS PrivateLink. But will AWS PrivateLink allow access to internet from my apps or can I use PrivateLink only for ECR image downloads from ECR and natgateway for occasional internet connectivity for my applications.
Thanks for your Valuable time.
You cannot access the internet outside of AWS services in a private instance if you're only using AWS PrivateLink.
You can download ECR images through VPC endpoints instead of a NAT gateway. The following endpoints are required:
com.amazonaws.region.ecr.dkr
com.amazonaws.region.ecr.api
com.amazonaws.region.ecr.s3
Reference: https://docs.aws.amazon.com/AmazonECR/latest/userguide/vpc-endpoints.html

List of AWS services that don’t require a VPC to run

Google failed me again or may be I wasnt too clear in my question.
Is there an easy way or rather how do we determine what services are VPC bound and what services are non-vpc ?
For example - EC2, RDS require a VPC setup
Lambda, S3 are publicly available services and doesn't need a VPC setup.
The basic services that require an Amazon VPC are all related to Amazon EC2 instances, such as:
Amazon RDS
Amazon EMR
Amazon Redshift
Amazon Elasticsearch
AWS Elastic Beanstalk
etc
These resources run "on top" of Amazon EC2 and therefore connect to a VPC.
There are also other services that use a VPC, but you would only use them if you are using some of the above services, such as:
Elastic Load Balancer
NAT Gateway
So, if you wish to run "completely non-vpc", then avoid services that are "deployed". It means you would use AWS Lambda for compute, probably DynamoDB for database, Amazon S3 for object storage, etc. This is otherwise referred to as going "serverless".