Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

A Simple AWS Lambda to compress images using imagemagick

The idea is to build a Lambda which will compress images using imagemagick

the steps involved are as follows 


  1. Create a source and destination S3 buckets
  2. when we upload a JPG file to source s3 bucket
  3. An event is triggered from the source S3 to the Lambda 
  4. the Lambda is responsible to read the source image and use imagemagick
    and compress and write back to destination S3 bucket 



1) Creating a S3 Bucket 

2) There are 3 ways in which a Lambda can be invoked

  1. using a trigger ( push mechnaism)
  2. pull mechanism like (SQS)
  3. direct invocation of Lambda
AWS gives many trigger points which can trigger a Lambda, In this we will choose an S3 Event

3) Code for Lambda
Code for the Lambda which gets triggered when a JPG file is uploaded to S3

4) aws lambda update-function-code --function-name images --s3-bucket purna-srcimages --s3-key file.zip --publish

5) Trigger the Lambda by uploading an image in source bucket , should compress and upload to the destination bucket

Dataframes in Pandas

SeriesPandas
In [7]:
print("hello")
hello
In [2]:
from pandas import Series
defaultSeries = Series([1,3,5,7,9])
defaultSeries
Out[2]:
0    1
1    3
2    5
3    7
4    9
dtype: int64
In [5]:
defaultSeries[2]
Out[5]:
5
In [9]:
seriesCustomIndex = Series([1,3,5], index = [ 'one','three', 'five'])
In [10]:
seriesCustomIndex
Out[10]:
one      1
three    3
five     5
dtype: int64
In [11]:
seriesCustomIndex['three']
Out[11]:
3
In [13]:
data = {
        'name':['purna','ramu','darshan'] ,
        'age':[37,37,37],
        'location':['vvn','kphb','kphb']
        }

from pandas import DataFrame
frame = DataFrame(data)
In [14]:
frame
Out[14]:
name age location
0 purna 37 vvn
1 ramu 37 kphb
2 darshan 37 kphb
In [15]:
new_frame = DataFrame(frame,columns=['name','location','age'])

new_frame
Out[15]:
name location age
0 purna vvn 37
1 ramu kphb 37
2 darshan kphb 37
In [16]:
new_frame('age')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-7148ce2a833a> in <module>
----> 1 new_frame('age')

TypeError: 'DataFrame' object is not callable
In [17]:
new_frame['age']
Out[17]:
0    37
1    37
2    37
Name: age, dtype: int64
In [18]:
 
C:\ProgramData\Anaconda34\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning: 
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
  """Entry point for launching an IPython kernel.
Out[18]:
name        darshan
location       kphb
age              37
Name: 2, dtype: object
In [19]:
new_frame.iloc[2]
Out[19]:
name        darshan
location       kphb
age              37
Name: 2, dtype: object
In [20]:
new_frame['Education']='MS'
In [21]:
new_frame
Out[21]:
name location age Education
0 purna vvn 37 MS
1 ramu kphb 37 MS
2 darshan kphb 37 MS
In [22]:
new_frame.T
Out[22]:
0 1 2
name purna ramu darshan
location vvn kphb kphb
age 37 37 37
Education MS MS MS
In [23]:
new_frame.T
Out[23]:
0 1 2
name purna ramu darshan
location vvn kphb kphb
age 37 37 37
Education MS MS MS
In [24]:
new_frame.T
Out[24]:
0 1 2
name purna ramu darshan
location vvn kphb kphb
age 37 37 37
Education MS MS MS
In [25]:
new_frame
Out[25]:
name location age Education
0 purna vvn 37 MS
1 ramu kphb 37 MS
2 darshan kphb 37 MS
In [31]:
new_frame.drop('location',axis=1)
Out[31]:
name age Education
0 purna 37 MS
1 ramu 37 MS
2 darshan 37 MS
In [34]:
new_frame.drop(1)
Out[34]:
name location age Education
0 purna vvn 37 MS
2 darshan kphb 37 MS
In [ ]:
 

Search 24 Bytes