public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonResourceGroupsTaggingAPIConfig config = new AmazonResourceGroupsTaggingAPIConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonResourceGroupsTaggingAPIClient client = new AmazonResourceGroupsTaggingAPIClient(creds, config); GetResourcesResponse resp = new GetResourcesResponse(); do { GetResourcesRequest req = new GetResourcesRequest { PaginationToken = resp.PaginationToken , ResourcesPerPage = maxItems }; resp = client.GetResources(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.ResourceTagMappingList) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.PaginationToken)); }
/// <summary> /// Returns all the tagged resources that are associated with the specified tags (keys /// and values) located in the specified region for the AWS account. The tags and the /// resource types that you specify in the request are known as <i>filters</i>. The response /// includes all tags that are associated with the requested resources. If no filter is /// provided, this action returns a paginated resource list with the associated tags. /// </summary> /// <param name="request">Container for the necessary parameters to execute the GetResources service method.</param> /// /// <returns>The response from the GetResources service method, as returned by ResourceGroupsTaggingAPI.</returns> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InternalServiceException"> /// The request processing failed because of an unknown error, exception, or failure. /// You can retry the request. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InvalidParameterException"> /// A parameter is missing or a malformed string or invalid or out-of-range value was /// supplied for the request parameter. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.PaginationTokenExpiredException"> /// A <code>PaginationToken</code> is valid for a maximum of 15 minutes. Your request /// was denied because the specified <code>PaginationToken</code> has expired. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.ThrottledException"> /// The request was denied to limit the frequency of submitted requests. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public virtual GetResourcesResponse GetResources(GetResourcesRequest request) { var marshaller = new GetResourcesRequestMarshaller(); var unmarshaller = GetResourcesResponseUnmarshaller.Instance; return(Invoke <GetResourcesRequest, GetResourcesResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the GetResources operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the GetResources operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public virtual Task <GetResourcesResponse> GetResourcesAsync(GetResourcesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new GetResourcesRequestMarshaller(); var unmarshaller = GetResourcesResponseUnmarshaller.Instance; return(InvokeAsync <GetResourcesRequest, GetResourcesResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// Initiates the asynchronous execution of the GetResources operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the GetResources operation on AmazonResourceGroupsTaggingAPIClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetResources /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public IAsyncResult BeginGetResources(GetResourcesRequest request, AsyncCallback callback, object state) { var marshaller = new GetResourcesRequestMarshaller(); var unmarshaller = GetResourcesResponseUnmarshaller.Instance; return(BeginInvoke <GetResourcesRequest>(request, marshaller, unmarshaller, callback, state)); }
/// <summary> /// Returns all the tagged or previously tagged resources that are located in the specified /// region for the AWS account. You can optionally specify <i>filters</i> (tags and resource /// types) in your request, depending on what information you want returned. The response /// includes all tags that are associated with the requested resources. /// /// <note> /// <para> /// You can check the <code>PaginationToken</code> response parameter to determine if /// a query completed. Queries can occasionally return fewer results on a page than allowed. /// The <code>PaginationToken</code> response parameter value is <code>null</code> <i>only</i> /// when there are no more results to display. /// </para> /// </note> /// </summary> /// <param name="request">Container for the necessary parameters to execute the GetResources service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the GetResources service method, as returned by ResourceGroupsTaggingAPI.</returns> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InternalServiceException"> /// The request processing failed because of an unknown error, exception, or failure. /// You can retry the request. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InvalidParameterException"> /// A parameter is missing or a malformed string or invalid or out-of-range value was /// supplied for the request parameter. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.PaginationTokenExpiredException"> /// A <code>PaginationToken</code> is valid for a maximum of 15 minutes. Your request /// was denied because the specified <code>PaginationToken</code> has expired. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.ThrottledException"> /// The request was denied to limit the frequency of submitted requests. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public virtual Task <GetResourcesResponse> GetResourcesAsync(GetResourcesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = GetResourcesRequestMarshaller.Instance; options.ResponseUnmarshaller = GetResourcesResponseUnmarshaller.Instance; return(InvokeAsync <GetResourcesResponse>(request, options, cancellationToken)); }
/// <summary> /// Returns all the tagged or previously tagged resources that are located in the specified /// region for the AWS account. You can optionally specify <i>filters</i> (tags and resource /// types) in your request, depending on what information you want returned. The response /// includes all tags that are associated with the requested resources. /// /// <note> /// <para> /// You can check the <code>PaginationToken</code> response parameter to determine if /// a query completed. Queries can occasionally return fewer results on a page than allowed. /// The <code>PaginationToken</code> response parameter value is <code>null</code> <i>only</i> /// when there are no more results to display. /// </para> /// </note> /// </summary> /// <param name="request">Container for the necessary parameters to execute the GetResources service method.</param> /// /// <returns>The response from the GetResources service method, as returned by ResourceGroupsTaggingAPI.</returns> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InternalServiceException"> /// The request processing failed because of an unknown error, exception, or failure. /// You can retry the request. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.InvalidParameterException"> /// A parameter is missing or a malformed string or invalid or out-of-range value was /// supplied for the request parameter. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.PaginationTokenExpiredException"> /// A <code>PaginationToken</code> is valid for a maximum of 15 minutes. Your request /// was denied because the specified <code>PaginationToken</code> has expired. /// </exception> /// <exception cref="Amazon.ResourceGroupsTaggingAPI.Model.ThrottledException"> /// The request was denied to limit the frequency of submitted requests. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public virtual GetResourcesResponse GetResources(GetResourcesRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = GetResourcesRequestMarshaller.Instance; options.ResponseUnmarshaller = GetResourcesResponseUnmarshaller.Instance; return(Invoke <GetResourcesResponse>(request, options)); }
/// <summary> /// Initiates the asynchronous execution of the GetResources operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the GetResources operation on AmazonResourceGroupsTaggingAPIClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetResources /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resourcegroupstaggingapi-2017-01-26/GetResources">REST API Reference for GetResources Operation</seealso> public virtual IAsyncResult BeginGetResources(GetResourcesRequest request, AsyncCallback callback, object state) { var options = new InvokeOptions(); options.RequestMarshaller = GetResourcesRequestMarshaller.Instance; options.ResponseUnmarshaller = GetResourcesResponseUnmarshaller.Instance; return(BeginInvoke(request, options, callback, state)); }
public async Task <string> GetKmsIdAsync() { if (!string.IsNullOrEmpty(_kmsId)) { return(_kmsId); } using (var taggingClient = new AmazonResourceGroupsTaggingAPIClient()) { var getResourcesRequest = new GetResourcesRequest { TagFilters = new List <TagFilter> { new TagFilter() { Key = KmsIdTagKey } } }; var resourcesResponse = await taggingClient.GetResourcesAsync(getResourcesRequest); if (resourcesResponse.ResourceTagMappingList.Count > 0) { var first = resourcesResponse.ResourceTagMappingList.First(); _kmsId = first.ResourceARN.Split('/').Last(); return(_kmsId); } } using (var kmsClient = new AmazonKeyManagementServiceClient()) { var createKeyRequest = new CreateKeyRequest { Description = "Key for .NET integration tests.", Origin = OriginType.AWS_KMS, KeyUsage = KeyUsageType.ENCRYPT_DECRYPT, Tags = new List <Tag> { new Tag() { TagKey = KmsIdTagKey, TagValue = string.Empty } } }; var response = await kmsClient.CreateKeyAsync(createKeyRequest); _kmsId = response.KeyMetadata.KeyId; return(_kmsId); } }
private IEnumerable <Resource> GetResources() { var request = new GetResourcesRequest { RestApiId = restApiId }; do { var response = Client.GetResources(request); request.Position = response.Position; foreach (var r in response.Items) { yield return(r); } } while (!string.IsNullOrEmpty(request.Position)); }
public async Task <List <ResourceData> > Handle(GetResourcesRequest request, CancellationToken cancellationToken) { return(await dbContext.Resources.ProjectTo <ResourceData>(autoMapper.ConfigurationProvider).ToListAsync(cancellationToken)); }
public Task <QueryResult <IReadOnlyCollection <Resource>, BewatchThatError> > Handle(GetResourcesRequest request, CancellationToken cancellationToken) => resourceStore.GetAsync(cancellationToken);
public Task <ResultContainer <ResourceModel[]> > GetResources([FromBody] GetResourcesRequest model) { return(api.Group("ResourceGroup").Action <GetResourcesRequest, ResourceModel[]>("GetResources").Execute(model)); }
static void Main(string[] args) { var config = CreateConfiguration(); var rootDir = Directory.GetCurrentDirectory(); var awsRegion = RegionEndpoint.GetBySystemName(config.AWS.DefaultRegion); var awsCredential = new BasicAWSCredentials(config.AWS.Credentials.AccessKeyId, config.AWS.Credentials.SecretAccessKey); //checking package file System.Console.WriteLine("checking package file..."); if (File.Exists(config.PackagePath) == false) { System.Console.WriteLine("package file does not exists."); System.Environment.Exit(1); return; } var appPackage = new AppPackage(config.PackagePath); var functionARN = ""; //creating lambda function using (var lambdaClient = new AmazonLambdaClient(awsCredential, awsRegion)) { //checking lambda function System.Console.WriteLine("checking if lambda function exists..."); var getFunctionResponse = lambdaClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetFunctionConfigurationAsync(config.AWS.Lambda.FunctionName)); }) .Result; if (getFunctionResponse.HttpStatusCode != HttpStatusCode.OK && getFunctionResponse.HttpStatusCode != HttpStatusCode.NotFound) { ExitDueUnexpectedResponse(getFunctionResponse); return; } //function does not exists, create a new if (getFunctionResponse.HttpStatusCode == HttpStatusCode.NotFound) { System.Console.WriteLine("lambda function does not exists, creating function...."); var createFunctionResponse = lambdaClient .ExecuteWithNoExceptionsAsync(c => { return(c.CreateFunctionAsync(appPackage, config.AWS.Lambda, Runtime.Dotnetcore20)); }) .Result; //checking create function response if (createFunctionResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(createFunctionResponse); return; } System.Console.WriteLine("lambda function created with success."); functionARN = createFunctionResponse.FunctionArn; } else { functionARN = getFunctionResponse.FunctionArn; } //checking if is new package var hashFilePath = $"{rootDir}/package.hash"; var isSamePackage = false; if (File.Exists(hashFilePath)) { var currentHash = File.ReadAllText(hashFilePath); isSamePackage = appPackage.PackageSha256.Equals(currentHash); } if (getFunctionResponse.HttpStatusCode == HttpStatusCode.OK) { functionARN = getFunctionResponse.FunctionArn; if (isSamePackage == false) { System.Console.WriteLine("lambda function exists, updating lambda function code..."); var updateCodeResponse = lambdaClient .ExecuteWithNoExceptionsAsync(c => { return(c.UpdateFunctionCodeAsync(appPackage, config.AWS.Lambda)); }) .Result; if (updateCodeResponse.HttpStatusCode != HttpStatusCode.OK) { ExitDueUnexpectedResponse(updateCodeResponse); return; } System.Console.WriteLine("lambda function code updated with success."); } else { System.Console.WriteLine("lambda function exists and its code is updated."); } } if (isSamePackage == false) { File.WriteAllText(hashFilePath, appPackage.PackageSha256); } } using (var gatewayClient = new AmazonAPIGatewayClient(awsCredential, awsRegion)) { //checking if api exists System.Console.WriteLine("checking existence of api gateway..."); var listApiResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetRestApisAsync(config.AWS.ApiGateway.GatewayName)); }) .Result; if (listApiResponse.HttpStatusCode != HttpStatusCode.OK) { ExitDueUnexpectedResponse(listApiResponse); return; } //creating api var restApi = listApiResponse.Items.SingleOrDefault(); if (restApi == null) { System.Console.WriteLine("api gateway does not exists, creating api gateway..."); var createApiResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.CreateRestApiAsync(config.AWS.ApiGateway.GatewayName)); }) .Result; if (createApiResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(createApiResponse); return; } restApi = new RestApi { Id = createApiResponse.Id, Name = config.AWS.ApiGateway.GatewayName }; } else { System.Console.WriteLine("api gateway - OK"); } //checkig if resource exists System.Console.WriteLine("checking existence of api resource..."); var listResourceRequest = new GetResourcesRequest() { RestApiId = restApi.Id, }; var listResourceResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetResourcesAsync(listResourceRequest)); }) .Result; if (listResourceResponse.HttpStatusCode != HttpStatusCode.OK) { ExitDueUnexpectedResponse(listResourceResponse); return; } var rootResource = listResourceResponse.Items.GetRootResource() ?? throw new System.Exception($"root resource can't be found on api:{restApi.Id}"); var proxyResource = listResourceResponse.Items.GetProxyResource(); if (proxyResource == null) { //creating resource System.Console.WriteLine("api resource not found, creating api resource..."); var createResourceResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.CreateProxyResourceAsync(restApi.Id, rootResource.Id)); }) .Result; if (createResourceResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(createResourceResponse); return; } proxyResource = createResourceResponse.MapToResource(); System.Console.WriteLine("api resource created."); } else { System.Console.WriteLine("api resource - OK"); } //checking if methods were created System.Console.WriteLine("checking if resource methods exists..."); var getMethodRequest = new GetMethodRequest() { HttpMethod = AmazonModelExtensions.ANY_METHOD, ResourceId = proxyResource.Id, RestApiId = restApi.Id }; var getMethodResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetMethodAsync(getMethodRequest)); }) .Result; if (getMethodResponse.HttpStatusCode != HttpStatusCode.OK && getMethodResponse.HttpStatusCode != HttpStatusCode.NotFound) { ExitDueUnexpectedResponse(getMethodResponse); return; } if (getMethodResponse.HttpStatusCode == HttpStatusCode.NotFound) { System.Console.WriteLine("resource methods does not exists, creating resource methods...."); var putMethodResponse = gatewayClient.ExecuteWithNoExceptionsAsync ( c => { return(c.PutProxyMethodAsync(proxyResource.Id, restApi.Id, AmazonModelExtensions.ANY_METHOD, "proxy")); } ) .Result; if (putMethodResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(putMethodResponse); return; } System.Console.WriteLine("resource method created with success"); } else { System.Console.WriteLine("resource methods - OK"); } //checking integration with lambda function System.Console.WriteLine("checking if integration with lambda exists..."); var getIntegrationRequest = new GetIntegrationRequest() { HttpMethod = AmazonModelExtensions.ANY_METHOD, ResourceId = proxyResource.Id, RestApiId = restApi.Id }; var getIntegrationResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetIntegrationAsync(getIntegrationRequest)); }) .Result; if (getIntegrationResponse.HttpStatusCode != HttpStatusCode.OK && getIntegrationResponse.HttpStatusCode != HttpStatusCode.NotFound) { ExitDueUnexpectedResponse(getIntegrationResponse); return; } if (getIntegrationResponse.HttpStatusCode == HttpStatusCode.NotFound) { System.Console.WriteLine("integration with lambda does not exists, creating integration..."); var putIntegrationResponse = gatewayClient.ExecuteWithNoExceptionsAsync ( c => { return(c.PutLambdaProxyIntegrationAsync ( proxyResource.Id, restApi.Id, AmazonModelExtensions.ANY_METHOD, config.AWS.Lambda.FunctionTimeoutSeconds.Value * 1000, functionARN, config.AWS.DefaultRegion )); } ) .Result; if (putIntegrationResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(putIntegrationResponse); return; } System.Console.WriteLine("integration with lambda created with success"); } else { System.Console.WriteLine("integration with lambda - OK"); } //checking deployment System.Console.WriteLine("checking api gateway deployment..."); var getDeployRequest = new GetDeploymentsRequest() { RestApiId = restApi.Id }; var getDeployResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.GetDeploymentsAsync(getDeployRequest)); }) .Result; if (getDeployResponse.HttpStatusCode != HttpStatusCode.OK) { ExitDueUnexpectedResponse(getDeployResponse); return; } var deployment = (Deployment)null; if (getDeployResponse.Items.Count == 0) { System.Console.WriteLine("api gateway deployment not found, deploying api gateway..."); var createDeployRequest = new CreateDeploymentRequest() { RestApiId = restApi.Id, StageName = config.ASPNETCORE_ENVIRONMENT, StageDescription = config.ASPNETCORE_ENVIRONMENT, }; var createDeployResponse = gatewayClient .ExecuteWithNoExceptionsAsync(c => { return(c.CreateDeploymentAsync(createDeployRequest)); }) .Result; if (createDeployResponse.HttpStatusCode != HttpStatusCode.Created) { ExitDueUnexpectedResponse(createDeployResponse); return; } System.Console.WriteLine("api gateway deployed with success."); } else { deployment = getDeployResponse.Items[0]; System.Console.WriteLine("api gateway deployment - OK"); } using (var lambdaClient = new AmazonLambdaClient(awsCredential, awsRegion)) { System.Console.WriteLine("grating permission to api gateway trigger lambda..."); var permissionResponse = lambdaClient.ExecuteWithNoExceptionsAsync ( c => { return(c.AddExecuteApiPermissionAsync ( config.AWS.Lambda, restApi.Id, config.AWS.DefaultRegion, config.AWS.AccountId )); } ) .Result; if (permissionResponse.HttpStatusCode != HttpStatusCode.Created && permissionResponse.HttpStatusCode != HttpStatusCode.Conflict) { ExitDueUnexpectedResponse(permissionResponse); return; } if (permissionResponse.HttpStatusCode == HttpStatusCode.Conflict) { System.Console.WriteLine("permission already granted."); } else { System.Console.WriteLine("permission granted with success."); } } } }