/aws_resources_guest_user.cs Secret
Created
June 24, 2023 20:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Amazon; | |
using Amazon.CognitoIdentity; | |
using UnityEngine; | |
using Amazon.Lambda; | |
using Amazon.Lambda.Model; | |
using System.Threading.Tasks; | |
using System.Text; | |
public class InvokeLambdaGuestUser : MonoBehaviour | |
{ | |
async void Start() | |
{ | |
string invokeResult = await InvokeLambdaFunction(); | |
print($"Invoking Lambda function: {invokeResult}"); | |
} | |
private async Task<string> InvokeLambdaFunction() | |
{ | |
// Building AWS Credentials | |
CognitoAWSCredentials credentials = new CognitoAWSCredentials( | |
"us-east-1:40f5ec2d-3eda-4b6f-ae9d-562a9768f17f", // Your Identity Pool ID here | |
RegionEndpoint.USEast1 // Your region here | |
); | |
// Building Lambda Client | |
AmazonLambdaClient client = new AmazonLambdaClient(credentials, RegionEndpoint.USEast1); | |
InvokeRequest request = new InvokeRequest | |
{ | |
FunctionName = "awsResourcesFunction", | |
InvocationType = InvocationType.RequestResponse | |
}; | |
// Invoking Lambda function | |
InvokeResponse response = await client.InvokeAsync(request); | |
if (response.FunctionError == null && response.StatusCode == 200) | |
{ | |
return Encoding.ASCII.GetString(response.Payload.ToArray()); | |
} | |
return "Error invoking Lambda function."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment