Find CodePipeline CIDR to add it to EC2 Security Group inbound rules - amazon-ec2

We are using AWS CodePipeline and at the build step we want to call an API hosted on an EC2 instance. That EC2 instance has a security group with some inbound rules. Is there any way to find out CIDR of the CodeBuild docker fleet, so we can add it to EC2 security group inbound rules, so that every stage from CodePipeline can call that API?

The range of public IP addresses used by the AWS CodeBuild build fleet is published here: http://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html
You can use the published range for each region in your security group rules.

Related

Security Group update to allow AWS Lambda function that is not attached to any VPC

There are two applications. One application is developed through AWS Lambda (present in Account A) and other application is deployed in ECS Fargate (present in Account B) in AWS.
The first application (AWS Lambda) is consuming an API (from the second application ECS Fargate). I need to allow the AWS Lambda function to access the ECS application (which is behind Application Load balancer) through the inbound rule in the security group.
Problem is AWS Lambda is not attached to any VPC and both applications are running in separate AWS accounts. How to solve this problem?
Note: It is an internal application not internet facing.
Note : Its internal application not internet facing.
If your ECS application's load balancer scheme is set to internal instead of public, then an AWS Lambda function that is not assigned to a VPC would never be able to access it. You are asking about security group rules, but there is no security group rule that will give something on the Internet access to a resource that is not exposed to the Internet.
Your only option to make this work is to move the Lambda function into a VPC, and establish VPC peering between the two VPCs.

EC2 Instance call from lamda function

hello I want to call a api which is hoisted in Apache server on AWS EC2 server from my lambda function.
I have configured VPC for my lambda function according to my EC2 server instance with same security groups and same zone ,but still no luck.
Thanks in advance.
It appears that your situation is:
You want to make an HTTP/S API call from an AWS Lambda function to an Amazon EC2 instance
The Lambda function has been configured to connect to the same VPC as the EC2 instance
The Lambda function is reporting that it is unable to connect to the EC2 instance
I would recommend:
Create a Security Group (let's call it Lambda-SG) in the same VPC. It does not need any rules.
Configured the Lambda function to use the Security Group (in the Network section)
Create another Security Group (let's call it EC2-SG) and associate it with the EC2 instance. Add a rule that permits inbound access on the desired port, with the source set to ID of Lambda-SG.
That is the EC2-SG is saying that it will accept inbound connects from Lambda-SG on the desired port.
Merely putting resources in the same security group does not necessarily mean they can communicate. There needs to be a specific rule that permits the inbound access. The above method is the best way to do so.

aws lambda access ec2

I have a python script running on AWS Lambda that tries to connect to a MariaDB I set up on an EC2 Instance.
The script can't execute because the security group of my EC2 instance only allows certain IPs. How can I allow Lambda functions to access?
The recommended way is to place your Lambda inside VPC. This will allow you to choose a subnet and a security group for your Lambda. So all you need to do after that is to modify your EC2 security group to allow connections either from the Lambda subnet (not so good) or from the Lambda security group (much better).

What is the downside of NOT running AWS Lambda functions in a VPC?

I am running AWS Lambda functions in a VPC.
And during the course of the project I have hit problems because:
no access to my database - had to solve this somehow
no access to AWS SES - had to find workaround
no access to AWS SQS -removed all queuing functionality from Lambda functions
no access to external Internet - still don't know how to implement ReCapthca
without Internet access
no access to AWS Cognito - cannot get
information about logged in users
I COULD implement a NAT gateway in the VPC but what is the point of serverless if I have to run a NAT server instance? That's not serverless.
So finally AWS has worn me down and I have decided to give up on running my AWS Lambda functions in a VPC - without endpoints for Internet proxying and the various AWS services its just too hard.
SO my question is - what is the downside/disadvantage of running my AWS Lambda functions with no VPC?
If you need access to resources within a VPC, then run your AWS Lambda function within a VPC. If you do not require this access, then do not run it within a VPC.
If you require Internet access, then you should connect your Lambda functions to a Private Subnet and use a NAT Gateway, which is a fully-managed NAT so you can remain serverless. It will solve the problems you listed.
AWS has provided a reference document for Lambda deployments: Serverless Application Lens, AWS Well-Architected Framework. In it they provide the following decision tree:
The only major downside noted is that a Lambda outside of a VPC cannot directly access private resources within a VPC.
One reason to create a Lambda in a VPC would be that you have a specific IP or IP range for it. This could be the case if a system just accepts calls from a specific IP which would need to be whitlistet for it.
Fix IP for Lambda function is discussed here: Is there a way to assign a Static IP to a AWS Lambda without VPC?
Downside of not having Lambda in VPC: Not having specific IP / IP-range for your Lambda function.
In the end I stayed with the VPC but I added an EC2 instance into the VPC and ran TinyProxy on it. I then configured my AWS Lambda functions with the environment variable:
HTTPS_PROXY https://ip-10-0-1-53.eu-west-1.compute.internal:8888
boto3 picked up the environment variable and sent all requests to the proxy. This seems to work fine without the complexity of a NAT gateway.

How to create an Amazon VPC using AWS CloudFormation?

I am currently using AWS CloudFormation for my application. Right now I am able to auto scale the instances. Now, I want to put every thing on an Amazon VPC. Can we create a VPC using CloudFormation? And how can we manage the Elastic IP address via CloudFormation, when we have an ELB in the template? I have found a VPC related example on AWS CloudFormation Sample Templates, but it only provisions resources into an existing VPC and doesn't create a new one in the template.
Update
As pointed out by Jeff already (+1), AWS has just announced AWS CloudFormation Support for Creating VPC Resources as of April 25, 2012, covering the missing piece of their initial VPC support:
We are excited to announce that AWS CloudFormation now supports the
creation of Amazon Virtual Private Cloud (VPC) resources. [...]
Now, you can create new Virtual Private Clouds (VPC), subnets,
gateways, network ACLs, routes and route tables using CloudFormation
templates. [...]
[...] A CloudFormation can now fully represent your VPC configuration
along with all the resources needed to run your application in the
VPC.
See Jeff Barr's introductory post AWS CloudFormation Can Now Create Virtual Private Clouds for more details and examples. In particular, the AWS CloudFormation Sample Templates feature two new sample templates [...] to get you started as well:
VPC with a single EC2 Instance - Sample template showing how to create a VPC and add an EC2 instance with an Elastic IP address and a security group.
VPC with public and private subnets, an Elastic load Balancer, and an EC2 instance - Sample template showing how to create a VPC with multiple subnets. The first subnet is public and contains the load balancer, the second subnet is private and contains an EC2 instance behind the load balancer.
Initial Answer
I don't think creating an Amazon VPC with AWS CloudFormation is already supported.
While AWS has just announced AWS CloudFormation Support For VPC as of February 12, 2012 indeed, this covers existing resource types only:
All resource types such as Amazon EC2 instances, security groups and
Elastic IP addresses, Elastic Load Balancers, Auto Scaling Groups and
Amazon RDS Database instances can now be deployed into any existing
Amazon VPC using CloudFormation templates. The templates allow you to
run multi-tier web applications and corporate applications in a
private network. With Amazon VPC and CloudFormation, you can easily
control which resources you want to expose publicly and which ones
should be private.
Amazon VPC is notably absent from this list, which matches the fact that it isn't listed in the supported AWS Resource Types Reference either.
It's supported now: see AWS CloudFormation Support for Creating VPC Resources for details.

Resources