项目作者: toshi0607

项目描述 :
unzip uploaded zip file to another S3 bucket via AWS Lambda in Go
高级语言: Go
项目地址: git://github.com/toshi0607/s3-unzipper-go.git
创建时间: 2018-08-07T13:37:05Z
项目社区:https://github.com/toshi0607/s3-unzipper-go

开源协议:

下载


s3-unzipper-go

Description

unzip uploaded zip file to another S3 bucket via AWS Lambda in Go

sequence

Production

prerequisites

You have to prepare credentials with proper policies.

And,

  • install aws-cli
  • install aws-sam-cli. Docker is also required. Follow the instruction here.
  • install direnv
  • install saw
    • you can watch CloudWatch logs on your terminal
  • set environment variables to .envrc.sample and remove .sample.
    • ZIPPED_ARTIFACT_BUCKET is S3 bucket name. It’s S3① in the sequence and should be unique globally.
    • UNZIPPED_ARTIFACT_BUCKET is S3 bucket name. It’s S3② in the sequence and should be unique globally.
    • STACK_BUCKET is S3 bucket name for artifacts of SAM and should be unique globally.

deploy

  1. $ dep ensure # to resolve dependency
  2. $ aws s3 mb "s3://${STACK_BUCKET}" # for artifacts of SAM
  3. $ make deploy

behavior

Deploy is required before checking behavior.

  1. $ saw groups
  2. /aws/lambda/stack-unzipper-lambda-Unzipper-XXXXXXXXXXXX
  3. $ saw watch /aws/lambda/stack-unzipper-lambda-Unzipper-XXXXXXXXXXXX
  4. # open another window
  5. $ aws s3 cp testdata/sample.zip "s3://${ZIPPED_ARTIFACT_BUCKET}"

Local

You can test a behavior on test (main_test.go).

In the test, setup prepares 2 real S3 buckets because SAM local doesn’t support local emulation of an S3.

One is for an even source that triggers an AWS Lambda and another is for a destination of unzipped artifacts.

Because S3 buckets created at the test are deleted on every test execution, idempotency is guaranteed.

Articles (Japanese)