prabhakar2020 / aws_lambda_function Goto Github PK
View Code? Open in Web Editor NEWAWS lambda function for S3 delete and copy data from source S3 to another target S3
AWS lambda function for S3 delete and copy data from source S3 to another target S3
error message
Test Event Name
deploy
Response
{
"errorMessage": "An error occurred (404) when calling the HeadObject operation: Not Found",
"errorType": "ClientError",
"requestId": "9c60ff97-5c61-4046-a240-f84677271370",
"stackTrace": [
" File "/var/task/lambda_function.py", line 16, in lambda_handler\n s3.meta.client.copy(copy_source, tgt_bucket_path, tgt_file_name)\n",
" File "/var/runtime/boto3/s3/inject.py", line 380, in copy\n return future.result()\n",
" File "/var/runtime/s3transfer/futures.py", line 103, in result\n return self._coordinator.result()\n",
" File "/var/runtime/s3transfer/futures.py", line 266, in result\n raise self._exception\n",
" File "/var/runtime/s3transfer/tasks.py", line 269, in _main\n self._submit(transfer_future=transfer_future, **kwargs)\n",
" File "/var/runtime/s3transfer/copies.py", line 118, in _submit\n response = call_args.source_client.head_object(\n",
" File "/var/runtime/botocore/client.py", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File "/var/runtime/botocore/client.py", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"
]
}
Function Logs
START RequestId: 9c60ff97-5c61-4046-a240-f84677271370 Version: $LATEST
[ERROR] ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 16, in lambda_handler
s3.meta.client.copy(copy_source, tgt_bucket_path, tgt_file_name)
File "/var/runtime/boto3/s3/inject.py", line 380, in copy
return future.result()
File "/var/runtime/s3transfer/futures.py", line 103, in result
return self._coordinator.result()
File "/var/runtime/s3transfer/futures.py", line 266, in result
raise self._exception
File "/var/runtime/s3transfer/tasks.py", line 269, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/var/runtime/s3transfer/copies.py", line 118, in _submit
response = call_args.source_client.head_object(
File "/var/runtime/botocore/client.py", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 719, in _make_api_call
raise error_class(parsed_response, operation_name)END RequestId: 9c60ff97-5c61-4046-a240-f84677271370
REPORT RequestId: 9c60ff97-5c61-4046-a240-f84677271370 Duration: 2095.08 ms Billed Duration: 2096 ms Memory Size: 128 MB Max Memory Used: 73 MB Init Duration: 269.78 ms
Request ID
9c60ff97-5c61-4046-a240-f84677271370
code
from future import print_function
import boto3
import time, urllib
import json
"""Code snippet for copying the objects from AWS source S3 bucket to target S3 bucket as soon as objects uploaded on source S3 bucket
@author: Prabhakar G
"""
print ("*"80)
print ("Initializing..")
print (""*80)
s3 = boto3.client('s3')
def lambda_handler(event, context):
# TODO implement
source_bucket = event['Records'][0]['s3']['bucket']['name']
object_key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'])
target_bucket = 'lambda-output-1'
copy_source = {'Bucket': source_bucket, 'Key': object_key}
print ("Source bucket : ", source_bucket)
print ("Target bucket : ", target_bucket)
print ("Log Stream name: ", context.log_stream_name)
print ("Log Group name: ", context.log_group_name)
print ("Request ID: ", context.aws_request_id)
print ("Mem. limits(MB): ", context.memory_limit_in_mb)
try:
print ("Using waiter to waiting for object to persist through s3 service")
waiter = s3.get_waiter('object_exists')
waiter.wait(Bucket=source_bucket, Key=object_key)
s3.copy_object(Bucket=target_bucket, Key=object_key, CopySource=copy_source)
return response['ContentType']
except Exception as err:
print ("Error -"+str(err))
return e
please help me out on this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.