HowTo AWS
Extraits de méthodes et de codes Utiles
Récupérer le Token d'un Switch Role
Permet de faire un Switch Rôle et de récupérer les credentials associés.
Nuget à installer :
https://www.nuget.org/packages/AWSSDK.SecurityToken/
using Amazon;
using Amazon.SecurityToken;
using Amazon.Runtime;
//needed info from target account
var targetRoleAccount = "434898027834";
var targetRoleName = "AAA_PE_MOBILE_SQUAD";
//my user creds
var mainAccountUserAccessToken = "AKIA6JEPFD7EUAPJORAI";
var mainAccountUserSecretToken = "*****************************";
//make some ARNs
var roleArn = $"arn:aws:iam::{targetRoleAccount}:role/{targetRoleName}";
var basicCreds = new BasicAWSCredentials(mainAccountUserAccessToken, mainAccountUserSecretToken);
var stsClient = new AmazonSecurityTokenServiceClient(basicCreds);
var sessionResponse = stsClient.GetSessionTokenAsync().Result;
var sessionCreds = new SessionAWSCredentials(sessionResponse.Credentials.AccessKeyId,
sessionResponse.Credentials.SecretAccessKey, sessionResponse.Credentials.SessionToken);
var options = new AssumeRoleAWSCredentialsOptions();
var assumeRoleCredentials = new AssumeRoleAWSCredentials(sessionCreds, roleArn, targetRoleName, options);
ImmutableCredentials credentials= assumeRoleCredentials.GetCredentials();
Installer les Templates AWS Lambda
La référence de cette page se trouve sur :
https://github.com/aws/aws-lambda-dotnet
Dotnet CLI Templates
New .NET Core projects can be created with the dotnet new command. By installing the Amazon.Lambda.Templates NuGet package the AWS Lamdba blueprints can be created from the dotnet new command. To install the template execute the following command:
Commande d'installation des templates
dotnet new -i "Amazon.Lambda.Templates::*"
The ::* on the end of the command indicates the latest version of the NuGet package.
To see a list of the Lambda templates execute dotnet new lambda --list
> dotnet new lambda --list
Templates Short Name Language Tags
---------------------------------------------------------------------------------------------------------------------------------------------------------
Order Flowers Chatbot Tutorial lambda.OrderFlowersChatbot [C#] AWS/Lambda/Function
Lambda Detect Image Labels lambda.DetectImageLabels [C#], F# AWS/Lambda/Function
Lambda Empty Function lambda.EmptyFunction [C#], F# AWS/Lambda/Function
Lex Book Trip Sample lambda.LexBookTripSample [C#] AWS/Lambda/Function
Lambda Simple DynamoDB Function lambda.DynamoDB [C#], F# AWS/Lambda/Function
Lambda Simple Kinesis Firehose Function lambda.KinesisFirehose [C#] AWS/Lambda/Function
Lambda Simple Kinesis Function lambda.Kinesis [C#], F# AWS/Lambda/Function
Lambda Simple S3 Function lambda.S3 [C#], F# AWS/Lambda/Function
Lambda Simple SQS Function lambda.SQS [C#] AWS/Lambda/Function
Lambda ASP.NET Core Web API serverless.AspNetCoreWebAPI [C#], F# AWS/Lambda/Serverless
Lambda ASP.NET Core Web Application with Razor Pages serverless.AspNetCoreWebApp [C#] AWS/Lambda/Serverless
Serverless Detect Image Labels serverless.DetectImageLabels [C#], F# AWS/Lambda/Serverless
Lambda DynamoDB Blog API serverless.DynamoDBBlogAPI [C#] AWS/Lambda/Serverless
Lambda Empty Serverless serverless.EmptyServerless [C#], F# AWS/Lambda/Serverless
Lambda Giraffe Web App serverless.Giraffe F# AWS/Lambda/Serverless
Serverless Simple S3 Function serverless.S3 [C#], F# AWS/Lambda/Serverless
Step Functions Hello World serverless.StepFunctionsHelloWorld [C#], F# AWS/Lambda/Serverless
To get details about a template, you can use the help command.
dotnet new lambda.EmptyFunction --help