amazon web services - AWS Lambda function unable to establish connection to SQL Server RDS instance -
i have written following small lambda function in .net core testing purposes. triggered on put in s3 bucket, , should show object name in cloudwatch , insert object name table in rds instance.
here code:
public async task<string> functionhandler(s3event evnt, ilambdacontext context) { context.logger.logline("context.logger.logline function begin"); var s3event = evnt.records?[0].s3; if(s3event == null) { context.logger.logline("no s3 events recorded"); return null; } try { var response = await this.s3client.getobjectmetadataasync(s3event.bucket.name, s3event.object.key); context.logger.logline("s3 key: " + s3event.object.key.tostring()); var connectionstring = environment.getenvironmentvariable("connectionstring"); sqlconnection c = new sqlconnection(connectionstring); c.open(); sqlcommand cmd = new sqlcommand("insert lambdatesttable (valuetext) values('" + s3event.object.key + "')", c); cmd.executenonquery(); c.close(); return response.headers.contenttype; } catch(exception e) { context.logger.logline($"error getting object {s3event.object.key} bucket {s3event.bucket.name}. make sure exist , bucket in same region function."); context.logger.logline(e.message); context.logger.logline(e.stacktrace); throw; } }
i following output in cloudwatch:
start requestid: 15c5eddb-8171-11e7-af34-251688cfddb2 version: $latest console.writeline function begin context.logger.logline function begin s3 key: tasktemplate.dp error found error getting object tasktemplate.dp bucket api-dev-dpstorage-s3. make sure exist , bucket in same region function. network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: tcp provider, error: 40 - not open connection sql server)
two errors unclear on here. firstly, while cloudwatch shows object key once file put bucket, has error saying can't find object? secondly, has network / instance error trying connect sql rds instance. using connection string used within ec2 instance application.
Comments
Post a Comment