Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Pass path argument(key) to Lambda using Boto3 and Invoke my Flask APP deployed as AWS Lambda ? #2225

Closed
SamvelChan opened this issue Dec 9, 2019 · 3 comments
Assignees
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made.

Comments

@SamvelChan
Copy link

I have flask add deployed as Lambda Function through Zappa. I want call lambda function exposing the end point /v1/key using boto3 and pass path argument(key). Can you please help me with it ?

Flask APP code
`
def create_app():

""" Create Flask application. """
app = Flask('myapp')
app.api = Api(app)
app.api.add_resource(Info, '/v1/path:key')
app.api.add_resource(Health, '/health')
return app

app=create_app()

@app.route('/')
def hello_world():
return jsonify({"message": "Hello World!"})

if name == 'main':
app.run()

class Info(SignatureSecuredResource):

def get(self, key):
log.info('key = %s' % key)

`

Boto3 invocation

`
import boto3
import json

if name == 'main':
# create lambda client
client = boto3.client('lambda',
region_name= 'us-east-1',
aws_access_key_id='',
aws_secret_access_key='
')
payload = {'key': 'test'}
payload = json.dumps(payload)
result = client.invoke(FunctionName='lambda-func',InvocationType='RequestResponse',
LogType='Tail',Payload=payload)
range = result['Payload'].read()
data = json.loads(range)
print(data)
`

@SamvelChan SamvelChan changed the title How to Pass path argument(key) using boto3 lambda invoke to my Flask APP deployed as AWS Lambda ? How to Pass path argument(key) to Lambda using Boto3 and Invoke my Flask APP deployed as AWS Lambda ? Dec 9, 2019
@swetashre
Copy link
Contributor

@SamvelChan - Thank you for your post. Your application needs to send it as part of the payload.
Basically the django app needs to provide in the payload any data your function needs. When you invoke lambda it will call your function handler. Your handler should process the payload as needed.

I found this post which explains this process step by step with code sample:
https://qxf2.com/blog/invoking-aws-lambda-functions-from-a-flask-app/

Hope it helps.

@swetashre swetashre self-assigned this Dec 12, 2019
@swetashre swetashre added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 12, 2019
@no-response
Copy link

no-response bot commented Dec 19, 2019

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made.
Projects
None yet
Development

No branches or pull requests

2 participants