Access S3 from a VPC¶
| Category | Cloud & AWS Networking |
| Status | โ Completed |
| Repo | nextwork-access-s3-from-a-vpc |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Access S3 from a VPC guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ Cloud & AWS Networking
Status: โ
Completed
Overview¶
This gets an EC2 instance inside a VPC talking to Amazon S3. The guide creates IAM access keys and runs aws configure on the instance. I deliberately swapped that for an IAM instance profile (temporary, auto-rotated credentials scoped to the one bucket), which is AWS best practice and means no long-lived keys exist to leak.
Summary¶
Deployed for real on AWS: an EC2 instance whose instance-profile role is scoped to one S3 bucket. From the instance I listed the bucket, uploaded a file and read a file. A ListAllMyBuckets call was denied, as intended. Everything was torn down afterwards.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Amazon VPC, Subnets, CIDR, Terraform, Infrastructure as Code, boto3, moto (AWS mock), Amazon S3, IAM instance profiles, Least privilege, Amazon EC2, AWS CLI
What I built¶
main.tf: VPC, public subnet and routing, an S3 bucket withnextwork-file-1.txtand-2.txt, an IAM role and policy scoped to the bucket, an instance profile, and an EC2 instance.checks.py: lists the files, runs theaws s3 cpequivalent, and verifies the instance profile and policy scope.
How to run¶
pip install -r requirements-dev.txt # moto (local AWS mock) + boto3
./local-test.sh # terraform apply against the mock, run checks.py, then destroy
# Real AWS (costs money; use your own IAM user/profile):
terraform init && terraform apply # mock_endpoint defaults to "" = real AWS
terraform destroy # clean up when done
Verification¶
I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.
PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh
Notes¶
- I didn't create access keys on purpose. If you follow the guide's access-key path, never put keys in code or Git, and delete them afterwards.
Real AWS deployment (2026-12-02)¶
I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-access-s3-from-a-vpc so I could prove nothing was left behind.
How I ran it: ./real-aws-run.sh (in this repo) does terraform init/apply with my AWS profile, runs checks.py against the real account, runs real-extra.sh for the live tests, and then always runs terraform destroy, even if a step fails. To get onto the instances I used EC2 Instance Connect with a throwaway SSH key that is only valid for 60 seconds. No key pairs were created in AWS and no keys were saved. Rather than the guide's access keys, the instance uses an IAM role, so there are no long-lived keys on the instance. My first run couldn't SSH in because the runner's outbound IP rotates, so SSH is now allowed from anywhere for the few minutes the instance exists. That's still only usable with a 60-second Instance Connect key.
Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):
$ python3 checks.py (against the real account)
ALL 4 CHECKS PASSED
$ ./real-extra.sh
+ aws sts get-caller-identity --query Arn --output text
+ sed -E 's/[0-9]{12}/<ACCOUNT_ID>/'
arn:aws:sts::<ACCOUNT_ID>:assumed-role/NextWorkEC2S3Access/i-072abeee4b0c9935e
+ aws s3 ls s3://nextwork-vpc-project-dfac8d67
2026-12-03 01:58:24 17 nextwork-file-1.txt
2026-12-03 01:58:24 17 nextwork-file-2.txt
2026-12-03 01:59:01 11 uploaded-from-ec2.txt
+ echo 'hi from EC2 in the NextWork VPC'
+ aws s3 cp /tmp/from-ec2.txt s3://nextwork-vpc-project-dfac8d67/
Completed 32 Bytes/32 Bytes (677 Bytes/s) with 1 file(s) remaining
upload: ../../tmp/from-ec2.txt to s3://nextwork-vpc-project-dfac8d67/from-ec2.txt
+ aws s3 ls s3://nextwork-vpc-project-dfac8d67
2026-12-03 01:59:09 32 from-ec2.txt
2026-12-03 01:58:24 17 nextwork-file-1.txt
2026-12-03 01:58:24 17 nextwork-file-2.txt
2026-12-03 01:59:01 11 uploaded-from-ec2.txt
+ aws s3 cp s3://nextwork-vpc-project-dfac8d67/nextwork-file-1.txt -
Hello from file 1+ aws s3 ls
+ tail -1
+ cut -c1-120
aws: [ERROR]: An error occurred (AccessDenied) when calling the ListBuckets operation: User: arn:aws:sts::<ACCOUNT_ID>:a
(the last call, ListAllMyBuckets, is denied on purpose: the role is scoped to this one bucket)
Teardown¶
Resources were up from 19:58 to 20:00 CST on 2026-12-02, then destroyed and verified gone:
=== TEARDOWN 2026-12-02 19:59 CST ===
$ terraform destroy -auto-approve -input=false -no-color -var ami_id=ami-000d209a4fc9822c4 -var project_tag=nextwork-access-s3-from-a-vpc -var ssh_cidr=0.0.0.0/0
Destroy complete! Resources: 16 destroyed.
$ terraform state list (should be empty)
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=nextwork-access-s3-from-a-vpc
$ live EC2 instances / volumes / VPCs tagged Project=nextwork-access-s3-from-a-vpc (should be empty)
=== teardown verified 20:00 CST ===
Cost¶
Estimated cost of the real run: about $0.01 (one t2.micro for about 2 minutes; S3 requests and storage are fractions of a cent). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.
Original project: https://nextwork.ai/projects/36d7dc8f-3a9f-51ff-91ae-662077ea9920 ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh
Success! The configuration is valid.
Apply complete! Resources: 15 added, 0 changed, 0 destroyed.
bucket = "nextwork-vpc-project-142d5289"
instance_id = "i-e5a5b089b3bae7945"
vpc_id = "vpc-77deca0ee4e26d782"
PASS: bucket holds the 2 project files (['nextwork-file-1.txt', 'nextwork-file-2.txt'])
PASS: aws s3 cp upload works
PASS: instance has the S3 instance profile (no static access keys)
PASS: role policy scoped to this bucket only
ALL 4 CHECKS PASSED
[exit code 0]