Sto tentando di accedere a S3 e risorse sul mio VPC da AWS Lambda ma da quando ho configurato il mio AWS Lambda per accedere a VPC è scaduto quando si accede a S3. Ecco il codiceL'aggiunta di AWS Lambda con configurazione VPC causa timeout durante l'accesso a S3
from __future__ import print_function
import boto3
import logging
import json
print('Loading function')
s3 = boto3.resource('s3')
import urllib
def lambda_handler(event, context):
logging.getLogger().setLevel(logging.INFO)
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')
print('Processing object {} from bucket {}. '.format(key, bucket))
try:
response = s3.Object(bucket, key)
content = json.loads(response.get()['Body'].read())
# with table.batch_writer() as batch:
for c in content:
print(' Processing Item : ID' + str(c['id']))
# ##################
# Do custom processing here using VPC resources
# ##################
except Exception as e:
print('Error while processing object {} from bucket {}. '.format(key, bucket))
print(e)
raise e
ho impostato il mio sottoreti e gruppi di protezione con appropriate regole in uscita per l'accesso a Internet come illustrato di seguito, ma la mia Lambda semplicemente volte su quando si accede S3.
Ecco un esempio di ingresso di test così
# Test Event Configuration
{
"Records": [
{
"awsRegion": "us-east-1",
"eventName": "ObjectCreated:Put",
"eventSource": "aws:s3",
"eventTime": "2016-02-11T19:11:46.058Z",
"eventVersion": "2.0",
"requestParameters": {
"sourceIPAddress": "54.88.229.196"
},
"responseElements": {
"x-amz-id-2": "ljEg+Y/InHDO8xA9c+iz6DTKKenmTaGE9UzHOAabarRmpDF1z0eUJBdpGi37Z2BU9nbTh4p7oZg=",
"x-amz-request-id": "3D98A2325EC127C6"
},
"s3": {
"bucket": {
"arn": "arn:aws:s3:::social-gauge-data",
"name": "social-gauge-data",
"ownerIdentity": {
"principalId": "A1NCXDU7DLYS07"
}
},
"configurationId": "b5540417-a0ac-4ed0-9619-8f27ba949694",
"object": {
"eTag": "9c5116c70e8b3628380299e39e0e9d33",
"key": "posts/test/testdata",
"sequencer": "0056BCDCF1F544BD71",
"size": 72120
},
"s3SchemaVersion": "1.0"
},
"userIdentity": {
"principalId": "AWS:AROAIUFL6WAMNRLUBLL3K:AWSFirehoseDelivery"
}
}
]
}
Grazie Marco. Ma penso che fosse più un problema sul modo in cui la mia Lambda si esibiva. Questo collegamento mi ha dato una migliore comprensione di cosa potrebbe accadere quando Lambda viene richiamata e sono stato in grado di risolverlo. https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ – blueskin
blueskin, sarebbe bello sapere come lo hai risolto ... – Aaron
il mio RDS è disponibile pubblicamente e lambda non è in vpc, ancora timeout. qualche idea? – johnny