How to enable VPC access for AWS CodeBuild/Code Pipeline? - amazon-web-services

How to enable VPC access for AWS CodeBuild/Code Pipeline?
I am working on the Neptune database and it requires VPC to access. While building code inside AWS CodeBuild. My tests are failing because it's not able to access the Neptune database. How can I configure the pipeline to allow CodeBuild to access the VPC?

This AWS Documentation guide will help you to configure your Code Build Project with your VPC.
But I am sure, you must have gone through it. Please share the error as well.
Link

Select environments from your CodeBuild project settings and in the advanced setting section you can select VPC, subnet and security group for your project.
For Subnets, choose a private subnet that has routes to your db. If internet access required, NAT gateway must be attached in the route table of private subnet. CodeBuild only works with Nat not with public subnet for internet access.

Be sure you have enabled AWS IAM authentication on your Neptune database config. You then need to allow the role you are running CodeBuild under to access that Neptune database. you will then be able to access it. Assuming it is an IAM error, please post more information if this is not the case. You will need to ensure the role you run as has the correct permissions to query Neptune.
There are detailed documents here on how to do this.
You can assign a managed policy to your role the following are available
NeptuneReadOnlyAccess
NeptuneFullAccess
NuptuneConsoleFullAccess <-- not really applicable to a CI process.

Related

Unable to Access IAM AWS Service Endpoint in a private subnet using a Private Link of VPC Endpoint

We're trying to access AWS Services from a private subnet in a VPC using a VPC endpoint or Private Link. We're trying to avoid adding a NAT gateway on the private subnet.
We created/added a VPC Endpoints (i.e. AWS Service for EC2 and S3)
com.amazonaws.us-east-2.ec2
com.amazonaws.us-east-2.s3
But we're not able to access something like com.amazonaws.us-east-2.iam; is there an iam endpoint or is this supported or is there any workaround
for us to use iam via VPC Endpoint on us-east-2?
Here's the error we're getting when we use the latest version of Java AWS SDK to get ec2 instance attached iam role programatically
org.apache.http.conn.ConnectTimeoutException: Connect to
iam.amazonaws.com:443 [iam.amazonaws.com/
Thanks for any information you can provide.
As of May 2022, VPC endpoint for IAM is not supported. You'd have to connect to IAM via internet. Or as a workaround, you can do IAM actions in CloudFormation.

AWS DynamoDB is always internet facing

Question
Tried to find a way to put DynamoDB in a VPC but could not find so far.
For Lambda, it can be inside a VPC with ENI having an IP from a VPC subnet, and then the Lambda does not have any internet connectivity without NAT.
Please confirm, DynamoDB has no such feature and it is always internet facing, although we can route the traffic not to go to the Internet via DynamoDB VPC endpoint.
That is correct. You can use IAM policies with conditions to limit access to within a VPC, however. Restricting Access to a Specific VPC
Your are right, DynamoDB always internet-facing. Is it bother you? Access to DynamoDB denied without IAM authentication
DynamoDB Preventative Security Best Practices -
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices-security-preventative.html
TLDR, main points -
1. Use IAM policy conditions for fine-grained access control
2. Use a VPC endpoint and policies to access DynamoDB
3. Encryption at rest
4. Use IAM roles

AWS Lambda Function Timeout on Connecting To RDS Database through RDS Proxy

I'm trying to test AWS RDS proxy so I created a lambda function and done all steps that are present in this official link
https://aws.amazon.com/blogs/compute/using-amazon-rds-proxy-with-aws-lambda
store RDS credentials in Secret Manager
create new role and also add Trust Policy
in lambda function, from the AWS console, add proxy and its status is available.
When I execute the lambda function, it times out with no errors it seems like the error might be on connecting to db with rds proxy because when I run the lambda function again without proxy, it works just fine.
I initially thought that it might be a security group issue, so I edit the security group of RDS Proxy and update inbound and allow 0.0.0.0 (outbound was already 0.0.0.0).
I used defaut VPC in RDS Database and RDS Proxy. The endpoint of RDS database is public.
Since RDS proxy is not available outside the VPC. Configure your lambda function to run inside the VPC. The following link will help:
https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html
Late answer.. thought these might help others.
You have to keep your lambdas inside the same VPC and subnets to access RDS proxy.
In any case if you want to access third party web api from your lambda, you have make the lambda subnets private (no Internet Gateway in route table) and assign a NAT gateway which is tied with a public subnet.
If you are accessing other AWS services which are out of VPC like S3, Secret Manager etc. then you have to create VPC endpoints for those services in your VPC.

ways to find all aws public resources?

I able to find that in my research there are some of the ways to find all our aws resources but will you suggest any solution to find public resources in aws our account.
Unfortunately, there is no easy way that you can find all resources that are allowed to communicate with outside world. However, the only way for most of the resources in AWS can connect to the internet through a VPC that is configured to allow access to 0.0.0.0/0 network with Security Group and ACL. So what you can do is to search for VPC ID on resources categories and if any results you get can connect to the internet.
This can be a very tedious task and this is NOT 100% guaranteed to find all resources as some resources has self-sustained VPC per resource such as S3. So my suggestion is you get used to using tags for resources.
Also maybe think about using infrastructure as code approach using something like Terraform.
If you have all of your instances in a VPC you could enable VPC Flow Logs on your VPC and then monitor all VPC traffic that way.
For the instances that are not in VPC's you could have CloudWatch logs enabled for that instance and then monitor the traffic that way.
Your instances should have security groups attached to them so that you could monitor the rules, and see if you have an OutBound Set to 0.0.0.0/0
You can give Netflix's Security Monkey a try. The tool will make a complete report of all secure and insecure AWS assets including Security Groups, IAM Policies and S3 Buckets. In fact, it also provides a ticketing like system to collab on such problems.
You can use IAM Access Analyzer console

Unable to access AWS SimpleDB from VPC enabled Lambda

I am facing a problem to access SimpleDB database from my VPC enabled Lambda function.
Below are the things which I have already done for VPC enabled lambda :
1. I have already set up my VPC configuration which includes NAT Gateway setting,Public and Private subnet and also Security Group and also created elastic IP for the same.
2. I have already tested my VPC enabled lambda by calling third party API to check internet access to my VPC enabled lambda and it is working fine.
3. I have also added SimpleDB permission policies for my VPC enabled Lambda role.
4. Also, I checked SimpleDB connection in lambda code without VPC and it is working fine.
But when I am trying to access SimpleDB with VPC enabled, it is resulting into timeout error.
Can anyone please help me out on this ?