Hey Jonathon! I’m trying to set up a lambda function to retrieve some data from a speckle stream.
I’m getting an error:
"errorType": "IOException",
"errorMessage": "Read-only file system : '/var/task/Speckle'",
"stackTrace": [
"at System.IO.FileSystem.CreateDirectory(String fullPath)",
"at System.IO.Directory.CreateDirectory(String path)",
"at Speckle.Core.Transports.SQLiteTransport..ctor(String basePath, String applicationName, String scope)",
"at Speckle.Core.Api.Operations.Receive(String objectId, CancellationToken cancellationToken, ITransport remoteTransport, ITransport localTransport, Action`1 onProgressAction, Action`2 onErrorAction, Action`1 onTotalChildrenCountKnown, Boolean disposeTransports, SerializerVersion serializerVersion)",
"at Speckle2Neo.Function.GetLatestCommitOnStream(Account account, String streamId, String branchName)",
"at Speckle2Neo.Function.FunctionHandler(String streamId, ILambdaContext context)",
"at lambda_method1(Closure , Stream , ILambdaContext , Stream )",
"at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145",
"at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 56",
"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176"
]
}
I’m assuming this is because only the tmp/ directory is writeable in AWS? What is speckle trying to write to file when receiving data?
What’s the recommendation for working with serverless functions (if there is one) in .net to access speckle data? Speckle.Core, REST, or GraphQL?
Any help would be appreciated.
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public async Task<string> FunctionHandler(string streamId, ILambdaContext context)
{
var account = new Account
{
token = "xxx",
serverInfo = new ServerInfo
{
url = "https://speckle.xyz/"
}
};
var client = new Client(account);
var data = await GetLatestCommitOnStream(account, streamId, "main");
var result = $"Latest commit id on branch {streamId}/main: { data.ToString()}";
return result;
}
private async Task<string> GetLatestCommitOnStream(Account account, string streamId, string branchName)
{
var client = new Client(account);
var branch = await client.BranchGet(streamId, branchName, 1);
var objectId = branch.commits.items[0].referencedObject; // take last commit
var transport = new ServerTransport(account, streamId);
var data = await Operations.Receive(
objectId,
remoteTransport: transport,
disposeTransports: true
);
var jsonData = System.Text.Json.JsonSerializer.Serialize( data );
return jsonData;
}
}