Skip to content

Commit

Permalink
Lambda for publishing a photo (#18)
Browse files Browse the repository at this point in the history
* Add lambda for publishing a photo
* Add lambda definition in CDK
  • Loading branch information
juanitodread committed Mar 15, 2024
1 parent c3b07be commit 51ff0ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt -t .; fi
zip -r pierrot-service.zip . -x 'cdk/\*' -x 'docs/\*'
zip -r pierrot-service.zip . -x 'cdk/*' -x 'docs/*'
- name: Deploy to AWS
- name: Deploy to AWS (Sync DB Lambda)
uses: appleboy/lambda-action@v0.1.9
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: us-east-1
function_name: pierrot-sync-db-dev
zip_file: pierrot-service.zip

- name: Deploy to AWS (Publish Photo Lambda)
uses: appleboy/lambda-action@v0.1.9
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: us-east-1
function_name: pierrot-publish-photo-dev
zip_file: pierrot-service.zip
9 changes: 9 additions & 0 deletions cdk/lib/pierrot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export class PierrotStack extends cdk.Stack {
handler: 'lambdas.sync_db.do_work',
runtime: lambda.Runtime.PYTHON_3_12,
code: lambda.Code.fromAsset('../pierrot-service.zip'),
timeout: cdk.Duration.seconds(60),
});

new lambda.Function(this, `PierrotPublishPhoto${environment}`, {
functionName: `pierrot-publish-photo-${environment.toLowerCase()}`,
handler: 'lambdas.publish_photo.do_work',
runtime: lambda.Runtime.PYTHON_3_12,
code: lambda.Code.fromAsset('../pierrot-service.zip'),
timeout: cdk.Duration.seconds(60)
});
}
}
29 changes: 29 additions & 0 deletions lambdas/publish_photo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pierrot.src.clients.flickr.client import Flickr
from pierrot.src.clients.s3.client import S3
from pierrot.src.clients.twitter.client import Twitter
from pierrot.src.config import Config
from pierrot.src.logging import get_logger
from pierrot.src.pierrot import Pierrot


log = get_logger(__name__)


def do_work(event, context) -> None:
log.info(f'Event: {event}, Context: {context}')

flickr_config = Config.get_flickr_config()
s3_config = Config.get_s3_config()
twitter_config = Config.get_twitter_config()

flickr = Flickr(flickr_config)
s3 = S3(s3_config)
twitter = Twitter(twitter_config)

pierrot = Pierrot(
flickr_username=flickr_config.photos_owner,
flickr=flickr,
s3=s3,
twitter=twitter,
)
pierrot.publish_photo()

0 comments on commit 51ff0ce

Please sign in to comment.