Skip to content

Instantly share code, notes, and snippets.

@radhakrishna4687
Forked from austoonz/PowerShellAssociation.yml
Created February 11, 2021 04:27
Show Gist options
  • Save radhakrishna4687/db76b53459b9276cb3cef5ecaa43d856 to your computer and use it in GitHub Desktop.
Save radhakrishna4687/db76b53459b9276cb3cef5ecaa43d856 to your computer and use it in GitHub Desktop.

Revisions

  1. @austoonz austoonz revised this gist Jul 11, 2019. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions Simple-S3Bucket-SNS
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,18 @@ Resources:
    Properties:
    # Need to define a static BucketName due to a circular dependency with the AWS::SNS::TopicPolicy
    BucketName: !Ref BucketName
    BucketEncryption:
    ServerSideEncryptionConfiguration:
    - ServerSideEncryptionByDefault:
    SSEAlgorithm: AES256
    AccessControl: BucketOwnerFullControl
    LifecycleConfiguration:
    Rules:
    -
    AbortIncompleteMultipartUpload:
    DaysAfterInitiation: 3
    NoncurrentVersionExpirationInDays: 3
    Status: Enabled
    LoggingConfiguration:
    DestinationBucketName: !Ref S3BucketLogs
    LogFilePrefix: !Sub '/logs/${BucketName}/'
  2. @austoonz austoonz revised this gist Jan 9, 2019. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions Simple-S3Bucket-SNS
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,14 @@ Parameters:

    BucketName:
    Type: String
    Description: S3 Bucket Name
    Description: The name of the S3 Bucket to create

    Metadata:

    AWS::CloudFormation::Interface:
    ParameterLabels:
    BucketName:
    default: S3 Bucket Name

    Resources:

    @@ -127,5 +134,7 @@ Outputs:
    S3Bucket:
    Value: !Ref S3Bucket
    Description: S3 Bucket for object storage
    Export:
    Name: S3Bucket

    SNSTopicArn:
    Value: !Ref SNSTopic
    Description: SNS Topic for S3 Object Triggers
  3. @austoonz austoonz created this gist Jan 9, 2019.
    131 changes: 131 additions & 0 deletions Simple-S3Bucket-SNS
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,131 @@
    ---
    AWSTemplateFormatVersion: '2010-09-09'

    Description: Simple S3 Bucket with SNS Trigger

    Parameters:

    BucketName:
    Type: String
    Description: S3 Bucket Name

    Resources:

    S3Bucket:
    Type: AWS::S3::Bucket
    DependsOn:
    - SNSTopicPolicy
    Properties:
    # Need to define a static BucketName due to a circular dependency with the AWS::SNS::TopicPolicy
    BucketName: !Ref BucketName
    AccessControl: BucketOwnerFullControl
    LoggingConfiguration:
    DestinationBucketName: !Ref S3BucketLogs
    LogFilePrefix: !Sub '/logs/${BucketName}/'
    NotificationConfiguration:
    TopicConfigurations:
    -
    Event: s3:ObjectCreated:Put
    Topic: !Ref SNSTopic
    PublicAccessBlockConfiguration:
    BlockPublicAcls: true
    BlockPublicPolicy: true
    IgnorePublicAcls: true
    RestrictPublicBuckets: true
    Tags:
    -
    Key: Description
    Value: Object Storage
    VersioningConfiguration:
    Status: Enabled

    SNSTopic:
    Type: AWS::SNS::Topic

    SNSTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties:
    Topics:
    - !Ref SNSTopic
    PolicyDocument:
    Id: SNSTopicPolicy
    Version: '2012-10-17'
    Statement:
    -
    Sid: S3TriggerAccess
    Effect: Allow
    Principal:
    AWS:
    - '*'
    Action:
    - sns:Publish
    Resource:
    - !Ref SNSTopic
    Condition:
    ArnLike:
    aws:SourceArn: !Sub "arn:aws:s3:::${BucketName}"
    # If you do not require cross-account subscriptions, this Policy can be removed
    -
    Sid: CrossAccountSubscriptionAccess
    Effect: Allow
    Principal:
    AWS:
    # List of AWS Accounts for cross-account subscriptions
    - !Sub 'arn:aws:iam::123456789012:root'
    Action:
    - sns:Subscribe
    - sns:Receive
    - sns:ListSubscriptionsByTopic
    Resource:
    - !Ref SNSTopic

    # If a source AWS Account is going to put objects into the Bucket, keep this resource,
    # if not, this BucketPolicy can be removed.
    S3BucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
    Bucket: !Ref S3Bucket
    PolicyDocument:
    Statement:
    -
    Sid: PutObjectAccess
    Action:
    - s3:PutObject
    Effect: Allow
    Principal:
    AWS:
    - '123456789012' # Replace with a valid source AWS Account Id
    Resource:
    - !Sub "arn:aws:s3:::${BucketName}"

    S3BucketLogs:
    Type: AWS::S3::Bucket
    Properties:
    AccessControl: LogDeliveryWrite
    LifecycleConfiguration:
    Rules:
    -
    AbortIncompleteMultipartUpload:
    DaysAfterInitiation: 7
    Status: Enabled
    Transitions:
    -
    StorageClass: GLACIER
    TransitionInDays: 30
    PublicAccessBlockConfiguration:
    BlockPublicAcls: true
    BlockPublicPolicy: true
    IgnorePublicAcls: true
    RestrictPublicBuckets: true
    Tags:
    -
    Key: Description
    Value: S3 Access Logs

    Outputs:

    S3Bucket:
    Value: !Ref S3Bucket
    Description: S3 Bucket for object storage
    Export:
    Name: S3Bucket