Node: AWS S3 sdk sync from different accounts - node.js

Hello I am having an issue with S3 buckets.
I have different environments dev, qa, staging and production, each s3 bucket have a specific IAM role per environment, so it won't be possible to share the same AWS Api keys.
What I need is the possibility to sync content from {ENV_1}_S3_Bucket to {ENV_2}_S3_Bucket using the nodejs aws sdk.
Is there anything that can help ? I wouldn't like to mess a lot with the IAM roles.
Thanks in advance and regards.

The role you want to access the bucket with must be explicit listed in the S3 Bucket Policy:
(S3 web console -> the bucket -> tab Permissions -> button Bucket Policy)
{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111111111111:role/your-bucket-role-1",
"arn:aws:iam::222222222222:role/your-bucket-role-1"
]
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::your-bucket",
"arn:aws:s3:::your-bucket/*"
]
}
]
}

Related

Allowing public-read and bucket-owner-full-control in S3

I'm trying to make a bucket of images public read even when uploaded from another AWS account. I have the current bucket policy in place:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mybucketname/*"
}
]
}
This works great when I upload using credentials from the primary account, but when I upload from the other account added by ACL it doesn't apply. As I read I found that you can add bucket-owner-full-control or public-read but not both. My end goal is to allow the object to be fully accesses by both AWS accounts AND have public read access on upload. Is this possible (ideally without two requests)?
The above accepted answer is incorrect as S3 bucket policies are ignored on objects published from another account.
The correct way to apply multiple ACLs on a cross account publish is like follows:
aws s3 cp --recursive blahdir s3://bucketname/blahdir/ --cache-control public,max-age=31536000 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers full=id=S3_ACCOUNT_CANONICAL_ID
No, it seems you can only specify one ACL when creating an object in Amazon S3.
For details of what each Canned ACL means, see: Canned ACL
For details of how ownership works, see: Amazon S3 Bucket and Object Ownership
Personally, I would not recommend using ACLs to control access. They are a hold-over from the early days of Amazon S3. These days, I would recommend using a Bucket Policy if you wish to make a large number of objects public, especially if they are in the same bucket/path.
Thus, an object can be uploaded with bucket-owner-full-control and the Bucket Policy can make them publicly accessible.

Custom IAM policy for RDS security group not working

Our project is currently hosted on AWS. We are using RDS service for data tier. I need to give permission to one of my IAM user to handle IP address addition/removal request for the security group associated with my RDS instance. Tried making custom policy for this case. Below is my JSON for policy -
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"rds:AuthorizeDBSecurityGroupIngress",
"rds:ListTagsForResource",
"rds:DownloadDBLogFilePortion",
"rds:RevokeDBSecurityGroupIngress"
],
"Resource": [
"arn:aws:rds:ap-south-1:608862704225:secgrp:<security-group name>",
"arn:aws:rds:ap-south-1:608862704225:db:<db name>"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"rds:DescribeDBClusterSnapshots",
"rds:DownloadCompleteDBLogFile"
],
"Resource": "*"
}
]
This isn't working despite various changes. Can anybody suggest where am I going wrong ? Any solution too would be welcomed.
Got the answer myself, actually was trying to make that work through permissions in RDS instance directly. Instead, security group permissions needs to be handled in ec2 policies.

How to mention elastic search roles serverless.yml

I'm working on an serverless project with aws-python3 template.
The lambda needs to write to amazon elastic search database.
So how do I mention these thing in serverless.yml file in iamroles section.
Build it up using CloudFormation syntax in the resources: section.
Below is an example IAM Policy that allows a Lambda function to write to an AWS ElasticSearch database.
I suggest you employ the use of the popular plugin serverless-pseudo-parameters to fill in the AccountID, Region, etc.
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"es:*"
],
"Resource": "arn:aws:es:us-west-1:987654321098:domain/test-domain/*"
}
]
}
Ref: https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-ac.html

S3 VPC end point Bucket policy

I have multiple EC2 instances originating form a single VPC and i want to assign a bucket policy to my s3 to make sure that only that VPC traffic will be allowed to access the bucket so i created an end point for that VPC and it added all the policies and routes in routing table. I assigned a following policy to my bucket
{
"Version": "2012-10-17",
"Id": "Policy1415115909153",
"Statement": [
{
"Sid": "Access-to-specific-VPCE-only",
"Action": "s3:*",
"Effect": "Allow",
"Resource": ["arn:aws:s3:::examplebucket",
"arn:aws:s3:::examplebucket/*"],
"Condition": {
"StringtEquals": {
"aws:sourceVpce": "vpce-111bbb22"
}
}
}
]
}
but it does not work when i connect to my Bucket using AWS-SDK for nodejs i get access denied error. The nodejs application is actually running in the Ec2 instance launched in same VPC as end point.
I even tried VPC level bucket policy but still i get access denied error. Can anyone tell me if i need to include any endpoint parameter in SDK S3 connection or any other thing?

Setting up Amazon Linux instance for CodeDeploy with IAM user credentials

I have created all that are needed for a successful deployment.
I tried to make the deployment without configuring the CodeDeploy agent in the Amazon instance and the deployment [obviously] failed.
After setting it up though, succeeded.
So, my question is, should I configure every instance that I use manually?
What if I have 100 instances in the deployment group?
Should I create an AMI with the CodeDeploy agent tool already configured?
EDIT
I have watched this:
https://www.youtube.com/watch?v=qZa5JXmsWZs
with this:
https://github.com/andrewpuch/code_deploy_example
and read this:
http://blogs.aws.amazon.com/application-management/post/Tx33XKAKURCCW83/Automatically-Deploy-from-GitHub-Using-AWS-CodeDeploy
I just cannot understand why I must configure with the IAM creds the instance. Isn't it supposed to take the creds from the role I launched it with?
I am not an expert in aws roles and policies, but from the CD documentation this is what I understood.
Is there a way to give the IAM user access to the instance so I wont have to setup the CD agent?
EDIT 2
I think that this post kind of answers: http://adndevblog.typepad.com/cloud_and_mobile/2015/04/practice-of-devops-with-aws-codedeploy-part-1.html
But as you can see, I launched multiple instances but I only installed CodeDeploy agent on one instance, what about others? Do I have to repeat myself and login to them and install them separately? It is OK since I just have 2 or 3. But what if I have handers or even thousand of instances? Actually there are different solutions for this. One of them is, I setup all environment on one instances and create an AMI from it. When I launch my working instance, I will create instance from the one I’ve already configured instead of the AWS default ones. Some other solutions are available
Each instance only requires the CodeDeploy agent installed on it. It does not require the AWS CLI to be installed. See AWS CodeDeploy Agent Operations for installation and operation details.
You should create an instance profile/role in IAM that will grant any instance the correct permissions to accept a code deployment through CodeDeploy service.
Create a role called ApplicationServer. To this role, add the following policy. This assumes you are using S3 for your revisions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::codedeploy-example-com/*"
]
},
{
"Sid": "Stmt1414002531000",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": [
"*"
]
},
{
"Sid": "Stmt1414002720000",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
}
]
}
To your specific questions:
So, my question is, should I configure every instance that I use
manually?
What if I have 100 instances in the deployment group? Should I create
an AMI with the aws-cli tool already configured?
Configure AMI with your base tools, or use CloudFormation or puppet to manage software installation on a given instance as needed. Again the AWS CLI is not required for CodeDeploy. Only the most current version of the CodeDeploy agent is required.

Resources