Add support for specifying an existing S3 bucket#29
Conversation
…e all bucket creation When ExistingBucketName is provided, no new S3 buckets are created anywhere in the stack — the SAM assessment bucket, SAM CLI artifacts bucket, and final report bucket all use the existing bucket. This supports customer environments with SCPs blocking bucket creation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@vardanmat - Thanks for submitting this PR. Can you please review the impact / changes on the SAM template for the scenario for a multi-account environment too. Documentation update will also be needed. Thank you ! |
Apply the same ExistingBucketName parameter pattern to the multi-account template (2-aiml-security-codebuild.yaml) for consistency with the single-account template.
|
@agasthik Updated this PR with: multi-account template support ( |
|
@vardanmat — One item to review and fix
The Suggested fix: Add CleanupBucketFunction:
Condition: CreateNewBucket
Type: AWS::Serverless::Function
...One-line change, no Lambda code modifications needed. |
|
@vardanmat — Minor UX suggestion (non-blocking): Consider adding an ExistingBucketName:
Type: String
Default: ""
Description: "Name of an existing S3 bucket to store assessment results (leave empty to create a new bucket)"
AllowedPattern: "^([a-z0-9][a-z0-9.-]{1,61}[a-z0-9])?$"
ConstraintDescription: "Bucket name must be 3-63 characters, lowercase letters/numbers/hyphens/dots only, starting and ending with a letter or number. Leave empty to create a new bucket."This isn't a security concern (IAM policy alone can't grant access to a bucket you don't own, and invalid names just 403 at runtime), but it gives users faster feedback if they typo the bucket name. |
|
@vardanmat — Good work on the feature. I ran a full review (static analysis with Agasthi already flagged the 🔴 CriticalC-01 —
|
| ID | Severity | Category | One-liner |
|---|---|---|---|
| C-01 | 🔴 Critical | Missing Feature | template-multi-account.yaml not updated — ExistingBucketName silently ignored, new bucket always created |
| H-01 | 🟠 High | IAM/Security | S3CrudPolicy grants DeleteObject on customer bucket (6 functions) |
| H-02 | 🟠 High | Design | Hardcoded role names — two stacks can't coexist in same account |
| H-03 | 🟠 High | Bug | Single-account sam deploy missing --region flag |
| H-04 | 🟠 High | Bug | SAM_PARAMS unquoted variable in buildspec |
| M-01 | 🟡 Medium | Bug | post_build bucket comparison fragile to empty/None ACCOUNT_BUCKET |
| M-02 | 🟡 Medium | Docs | CLI examples missing deployment/ path prefix |
| M-03 | 🟡 Medium | Docs | New section missing: permissions, region, artifacts, orphan warning |
| L-01 | 🔵 Low | Code Quality | DependsOn removal has no comment |
| L-02 | 🔵 Low | IAM | aiml-security-* wildcard grant always active |
| L-03 | 🔵 Low | IAM | s3:CreateBucket not scoped/conditional |
| L-04 | 🔵 Low | Code Quality | CreateNewBucket condition is redundant |
| I-01 | ℹ️ Info | Confirmed | Stack update existing→new works ✅ |
| I-02 | ℹ️ Info | Docs | Versioned bucket cleanup incomplete in README |
Summary
ExistingBucketNameparameter to single-account, multi-account, and SAM templatesbuildspec.ymlto pass--s3-bucketand--parameter-overridesto SAM deploy when an existing bucket is specifiedFiles changed
deployment/aiml-security-single-account.yaml— ExistingBucketName parameter, conditional bucket/policy, updated IAM and env varsdeployment/2-aiml-security-codebuild.yaml— same changes for multi-account templateaiml-security-assessment/template.yaml— conditional AIMLAssessmentBucket, updated Lambda env vars and policiesbuildspec.yml— conditional SAM deploy flags based on EXISTING_ASSESSMENT_BUCKET env varREADME.md— documentation for the new parameterTest plan