You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, if there's not image in this path, it's redirected to lambda and, after a moment, lambda creates the suitable image and then redirects back. We'll obviously have a new image next time.
36
15
37
-
Role policy document
16
+
***
17
+
Instead of `WxH` there're some extra available _magic paths_:
18
+
`.../AUTOx150/...`
19
+
`.../150xAUTO/...`
20
+
or
21
+
`.../150x150_max/...`
22
+
`.../150x150_min/...`
23
+
24
+
> Note that **s3-resizer****don't enlarge an image** if the original image width or height are already less than required dimensions. You can read about **[#withoutEnlargement](http://sharp.dimens.io/en/stable/api-resize/#withoutenlargement)** method.
25
+
26
+
27
+
## Setting up
28
+
29
+
#### To resize images we need a storage, which is _S3_, and _Lambda_ function. Then we should set up redirection rules.
30
+
31
+
* Create a **Bucket**
32
+
** Go to [Services -> Storage -> S3](https://s3.console.aws.amazon.com/s3/home)
33
+
** Click on the blue button **Create bucket**
34
+
** Enter the name and click on **Create**
35
+
36
+
* Create a **Lambda**
37
+
** Go to [Services -> Compute -> Lambda](https://console.aws.amazon.com/lambda/home)
38
+
** Click on the orange button **Create a function**
39
+
** In the next page, click on the similar button **Author from scratch**
40
+
** Add a trigger, which would listen to http requests (you also would be able to do it later)
41
+
*** On the dotted square choose **API Gateway**
42
+
*** You can use default **API name** or create new one
43
+
*** In **Security** select **Open**, then click **Next**
44
+
** In **Configure function** page
45
+
*** Name a new lambda
46
+
*** In **Runtime** select **Node.js 6.10**
47
+
*** Upload a _.zip_ file (download it from [releases](https://github.com/kofon95/s3-resizer/releases))
48
+
***> You'll also need to set up two **Environment variables**, with _BUCKET_ and _URL_ as keys. But in this time, you don't know about that _URL_. It is **endpoint** which you'll see below.
49
+
*** Choose role which has permission to put any object or create a new one. To do that
50
+
**** choose **Create a custom role** in role's list. It should open a new page in your browser. On that page
51
+
**** choose **Create a new IAM Role**
52
+
**** name you role, for example: *"access_to_putObject"*
53
+
**** Expand **View Policy Document**, click **Edit**, and write this content:
38
54
```json
39
55
{
40
56
"Version": "2012-10-17",
@@ -56,3 +72,98 @@ Role policy document
56
72
]
57
73
}
58
74
```
75
+
> Pay attention to `__BUCKET_NAME__`
76
+
77
+
*** That page should closes after that action. So go on creating a lambda. And take a look at **Advanced settings**
78
+
**** Allocate a memory 512
79
+
**** Timeout could be 5 seconds
80
+
> It's mooore than enough. And you shouldn't care of limits because images caches, which means lambda calls only for the first time.
81
+
*** Click **Next**, **Create function**. And wait for 20-30 seconds. Lambda is created.
82
+
83
+
***
84
+
85
+
* Public access to files in your bucket and relationships between lambda and bucket.
86
+
** Firstly, you need Lambda's _url_
87
+
*** Click the link of **API name** (in case you didn't change it in creating lambda, it should name like **LambdaMicroservice**)
88
+
*** On the new page, look for **Actions** button, select **Deploy API** and choose **prod** in **Deployment stage**. Then click **Deploy**
89
+
*** Expand **prod** in **Stages**, click on **GET** and copy URL that you see
90
+
** Open your created bucket -> Permissions -> Bucket Policy
91
+
** Paste this pease of code there and click **Save**
92
+
```json
93
+
{
94
+
"Version": "2012-10-17",
95
+
"Statement": [
96
+
{
97
+
"Sid": "AddPerm",
98
+
"Effect": "Allow",
99
+
"Principal": "*",
100
+
"Action": "s3:GetObject",
101
+
"Resource": "arn:aws:s3:::__BUCKET_NAME__/*"
102
+
}
103
+
]
104
+
}
105
+
```
106
+
> Pay attention to `__BUCKET_NAME__`. By the way, you're able to open access not to whole bucket but to specific directory specifying it instead of __*__.
107
+
* * Go to Properties (near to Permissions) -> Static website hosting -> Select **"Use this bucket to host a website"**
108
+
** In **Index document** paste any file, it'd be logical to name it _"index.html"_
0 commit comments