-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add serverless to proccess and storage image
- Loading branch information
Showing
8 changed files
with
331 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.serverless/ | ||
vendor/ | ||
bin/ | ||
*.swp | ||
config.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/aws/aws-lambda-go" | ||
version = "^1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
dep ensure | ||
env GOOS=linux go build -ldflags="-s -w" -o bin/leviathan main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# resize image | ||
|
||
### dependencies | ||
|
||
|
||
- [go](https://golang.org/) | ||
|
||
- [deb](https://github.com/golang/dep) | ||
|
||
- [aws cli]() setup with credentials | ||
|
||
- [serverless](https://serverless.com/blog/framework-example-golang-lambda-support/) | ||
|
||
### build | ||
> Make sure you're in your ```${GOPATH}/src``` directory, then run: | ||
```bash | ||
make | ||
sls deploy | ||
``` | ||
|
||
### Use | ||
|
||
Path: /upload | ||
Method: POST | ||
Paramethers: | ||
|
||
```php | ||
'file' => $file, | ||
's3_store' => [ | ||
'key' => config('filesystems.disks.s3.key'), | ||
'secret' => config('filesystems.disks.s3.secret'), | ||
'bucket' => config('filesystems.disks.s3.bucket'), | ||
'region' => config('filesystems.disks.s3.region'), | ||
'path' => /img/, | ||
'acl' => 'public_read', | ||
'headers' => [ | ||
"Cache-Control" => "max-age=630700000000", | ||
"Expires" => 2535321600, //year 2050 | ||
], | ||
], | ||
``` | ||
|
||
### Todo | ||
|
||
[ ] - endpoint to upload image to s3 | ||
[ ] - - save image to s3 | ||
[ ] - - save metadata (image, user, s3 destination credentials) | ||
[x] - lambda function to resize image on s3 | ||
[ ] - lambda function save results to s3 destination storaged | ||
[ ] - control and register user requests (API keys) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"SOURCE_S3_BUCKET_NAME": "{unique upload bucket name}", | ||
"DEST_S3_BUCKET_NAME": "{unique upload bucket name}", | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Welcome to Serverless! | ||
|
||
service: Leviathan | ||
|
||
custom: | ||
config: ${file(config.json)} | ||
|
||
provider: | ||
name: aws | ||
runtime: go1.x | ||
iamRoleStatements: | ||
- Effect: Allow | ||
Action: | ||
- "s3:*" | ||
Resource: "*" | ||
environment: | ||
SOURCE_S3_BUCKET_NAME: ${self:custom.config.SOURCE_S3_BUCKET_NAME} | ||
DEST_S3_BUCKET_NAME: ${self:custom.config.DEST_S3_BUCKET_NAME} | ||
|
||
package: | ||
exclude: | ||
- ./** | ||
include: | ||
- ./bin/** | ||
|
||
functions: | ||
leviathan: | ||
handler: bin/leviathan | ||
events: | ||
- s3: | ||
bucket: ${self:custom.config.SOURCE_S3_BUCKET_NAME} | ||
event: s3:ObjectCreated:* | ||
|
||
resources: | ||
Resources: | ||
DestImageBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: ${self:custom.config.DEST_S3_BUCKET_NAME} | ||
|