Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Latest commit

 

History

History
111 lines (81 loc) · 3.61 KB

README.md

File metadata and controls

111 lines (81 loc) · 3.61 KB

cfn-cr-bucket-tagger is deprecated

This project is deprecated and will no longer be maintained. The functionality of this bucket tagger has been moved to the cfn-cr-synapse-tagger


Cloudformation Custom Resource that sets tags for a S3 bucket.

Inventory of source code and supporting files:

  • set_bucket_tags - Code for the application's Lambda function.
  • events - Invocation events that you can use to invoke the function.
  • tests - Unit tests for the application code.
  • template.yaml - A template that defines the application's AWS resources.

The AWS SAM CLI is used to build and package the lambda code. The sceptre utility is used to deploy the macro that invokes the lambda as a CloudFormation stack.

Use in a Cloudformation Template

Create a custom resource in your cloud formation template. Here's an example:

  S3BucketTagger:
    Type: Custom::S3BucketTagger
    Properties:
      ServiceToken: !ImportValue
        'Fn::Sub': '${AWS::Region}-set-bucket-tags-macro-FunctionArn'
      BucketName: !Ref S3Bucket

The creation of the custom resource triggers the lambda, which pulls the current tags from S3Bucket, derives new tags, and sets those on the bucket. Currently the only new tag added is an OwnerEmail tag, whose value looks like [email protected], where the janedoe is a Synapse user name. Synapse provides email addresses for all user names.

Development

Contributions

Contributions are welcome.

Requirements

Run pipenv install --dev to install both production and development requirements, and pipenv shell to activate the virtual environment. For more information see the pipenv docs.

After activating the virtual environment, run pre-commit install to install the pre-commit git hook.

Create a local build

$ sam build --use-container

Run locally

$ sam local invoke SetBucketTagsFunction --event events/create.json

Run unit tests

Tests are defined in the tests folder in this project. Use PIP to install the pytest and run unit tests.

$ python -m pytest tests/ -v

Deployment

Build

sam build

Deploy Lambda to S3

This requires the correct permissions to upload to bucket bootstrap-awss3cloudformationbucket-19qromfd235z9.

sam package --template-file template.yaml \
  --s3-bucket essentials-awss3lambdaartifactsbucket-x29ftznj6pqw \
  --output-template-file .aws-sam/build/cfn-cr-bucket-tagger.yaml

aws s3 cp .aws-sam/build/cfn-cr-bucket-tagger.yaml s3://bootstrap-awss3cloudformationbucket-19qromfd235z9/cfn-cr-bucket-tagger/master

Install Lambda into AWS

Create the following sceptre file

config/prod/cfn-cr-bucket-tagger.yaml

template_path: "remote/set-bucket-tags-macro.yaml"
stack_name: "cfn-cr-bucket-tagger"
hooks:
  before_launch:
    - !cmd "curl https://s3.amazonaws.com/essentials-awss3lambdaartifactsbucket-x29ftznj6pqw/it-lambda-set-bucket-tags/master/cfn-cr-bucket-tagger.yaml --create-dirs -o templates/remote/cfn-cr-bucket-tagger.yaml"

Install the lambda using sceptre:

sceptre --var "profile=my-profile" --var "region=us-east-1" launch prod/cfn-cr-bucket-tagger

## Author

[Tess Thyer](https://github.com/tthyer); Principal Data Engineer, Sage Bionetworks