In this repository, we provide cross-account integration code samples using Access points, a feature provided by Amazon S3.
This repo is organized into following branches:
- main: It has code samples for AWS CLI and Java application
- main-emr: It has code sample for an Amazon EMR job.
Figure below represent AWS CLI and Java application
- The source code has Maven nature, so if you have Maven locally then you can build it using standard Maven commands e.g.
mvn -X clean install
. or use the options available in your IDE - This will generate a jar file called
s3-cross-account-access-points-0.1.jar
The following AWS services are required to demo/try this solution.
- One S3 Bucket
- One Bucket Policy
- Two Access Points
- One KMS Key to encrypt S3 bucket
- One IAM Group
- One IAM User
- One IAM Role
- One EC2 Instance
Class | Overview |
---|---|
PutObject_Demo_UsingIAMRole | Java class to upload an object to S3 - to be executed on an EC2 instance. |
PutObject_Demo_StandaloneUser | Java class to upload an object to S3 - to be executed on your Laptop / MacBook. |
- Login to AWS Console and go to IAM
- Create an IAM User Group with the following IAM Policies
- Create an IAM User and add it to the group created in Step # 2
- Create an IAM Role with two policies as follows:
- IAM Policy for S3. Use s3_policy_iam_role_ec2_instance as a sample
- IAM Policy for KMS. Use kms_key_policy as a sample
- Provision as EC2 Instance with the following settings
- t2.micro instance should be good enough
- the IAM Role created in Steps # 4
- Make sure the security allows inbound access only from your IP address
- Make a note of the public IP address
- Logon to AWS Console
- Go to KMS and create a Customer managed key
- For Key administrators, add required users / roles in Account A
- For Key users, add
- required users / roles in Account A
- under
Other AWS accounts
, add id for Account B e.g.arn:aws:iam::1234567890:root
- Go to S3 and create a bucket
- Go to Properties, under Default encryption, select AWS-KMS and select the KMS key created in the previous step
- Create a bucket policy using sample bucket_policy_delegate_permissions_to_access_point
- Create first access point using sample access_point_for_external_roles_sample
- Create second access point using samples access_point_for_external_users_sample
-
Pre-requisite: AWS CLI v2 is required on your on your Laptop / MacBook
-
Test # 1 - using AWS CLI v2 on your Laptop / MacBook
aws s3api put-object --bucket arn:aws:s3:us-east-1:2345678901:accesspoint/access-point-external-users --key <Object_Name> --body <Object_Path> --profile default
-
Test # 2 - using EC2 instance
-
Logon to EC2 Instance using the command below
ssh -i my_ec2_keypair.pem ec2-user@Public_IP_of_EC2
-
Install Open JDK v 1.8
-
Logout from EC2 Instance
-
Upload Jar file to EC2 instance
scp -i /Users/<Your_User_Id>/Downloads/my_ec2_keypair.pem s3-cross-account-access-points-0.1.jar ec2-user@<Public_IP_of_EC2>:/home/ec2-user/
-
Logon to EC2 Instance
-
Run the Java Program
java -jar s3-cross-account-access-points-0.1.jar arn:aws:s3:us-east-1:2345678901:accesspoint/access-point-external-roles from_ec2_instance us-east-1
-
Following people have contributed to this repo.
- Phanee Gottumukkala, Data & ML Engineer, AWS Professional Services
- Sunil Penumala, Data Architect, AWS Professional Services
- Ravi Itha, Sr. Data Architect, AWS Professional Services
This sample code is made available under the MIT license. See the LICENSE file.