Skip to content

parmarsuraj99/lambda-docker-template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Steps

  1. Build the docker image with a tag.
docker build -t ping .
  1. Run and ensure it works
docker run -p 8080:8080 ping

Test using requests

import requests
import json

data = {"text": "This is a message."}
response = requests.post('http://localhost:8080/2015-03-31/functions/function/invocations', json={'body': json.dumps(data)})
print(response.json())
  1. Create an ECR repo and set the AWS Region and Account ID and push the docker image to ECR.
export AWS_REGION=us-east-2
export AWS_ACCOUNT_ID=********
export TAG=ping
export ECR_REPO_NAME=ping

aws ecr create-repository --repository-name $ECR_REPO_NAME

aws ecr get-login-password \
    --region "$AWS_REGION" \
| docker login \
    --username AWS \
    --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"

docker tag $TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME

docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME
  1. Install serverless and deploy lambda function to AWS.
serverless deploy
  1. Try the API by calling endpoint given by serverless framework.
import requests
data = {"text": "This is a message."}

response = requests.post('https://******.execute-api.us-east-2.amazonaws.com/dev/ping', json=data)
print(response.json())

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 78.0%
  • Dockerfile 22.0%