Beispiel #1
0
 public MyStack()
 {
     var testRestApi = new Aws.ApiGateway.RestApi("testRestApi", new Aws.ApiGateway.RestApiArgs
     {
         Description = "This is my API for demonstration purposes",
     });
     var testDeployment = new Aws.ApiGateway.Deployment("testDeployment", new Aws.ApiGateway.DeploymentArgs
     {
         RestApi   = testRestApi.Id,
         StageName = "dev",
     }, new CustomResourceOptions
     {
         DependsOn =
         {
             "aws_api_gateway_integration.test",
         },
     });
     var testStage = new Aws.ApiGateway.Stage("testStage", new Aws.ApiGateway.StageArgs
     {
         Deployment = testDeployment.Id,
         RestApi    = testRestApi.Id,
         StageName  = "prod",
     });
     var testResource = new Aws.ApiGateway.Resource("testResource", new Aws.ApiGateway.ResourceArgs
     {
         ParentId = testRestApi.RootResourceId,
         PathPart = "mytestresource",
         RestApi  = testRestApi.Id,
     });
     var testMethod = new Aws.ApiGateway.Method("testMethod", new Aws.ApiGateway.MethodArgs
     {
         Authorization = "NONE",
         HttpMethod    = "GET",
         ResourceId    = testResource.Id,
         RestApi       = testRestApi.Id,
     });
     var methodSettings = new Aws.ApiGateway.MethodSettings("methodSettings", new Aws.ApiGateway.MethodSettingsArgs
     {
         MethodPath = Output.Tuple(testResource.PathPart, testMethod.HttpMethod).Apply(values =>
         {
             var pathPart   = values.Item1;
             var httpMethod = values.Item2;
             return($"{pathPart}/{httpMethod}");
         }),
         RestApi  = testRestApi.Id,
         Settings = new Aws.ApiGateway.Inputs.MethodSettingsSettingsArgs
         {
             LoggingLevel   = "INFO",
             MetricsEnabled = true,
         },
         StageName = testStage.StageName,
     });
     var testIntegration = new Aws.ApiGateway.Integration("testIntegration", new Aws.ApiGateway.IntegrationArgs
     {
         HttpMethod = testMethod.HttpMethod,
         ResourceId = testResource.Id,
         RestApi    = testRestApi.Id,
         Type       = "MOCK",
     });
 }
Beispiel #2
0
    private Output <string> CreateRestAPIGatewayResources(Function lambda)
    {
        var body = lambda.Arn.Apply(lambdaArn => $@"
                {{
                    ""swagger"" : ""2.0"",
                    ""info"" : {{""title"" : ""api"", ""version"" : ""1.0""}},
                    ""paths"" : {{
                        ""/{{proxy+}}"" : {{
                            ""x-amazon-apigateway-cors"":{{
                                ""allowOrigins"": ""*"",
                                ""allowMethodsd"": ""*"",
                                ""allowHeaders"": ""*""
                            }},                 
                            ""x-amazon-apigateway-any-method"" : {{
                                ""x-amazon-apigateway-integration"" : {{
                                    ""uri"" : ""arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/{lambdaArn}/invocations"",
                                    ""passthroughBehavior"" : ""when_no_match"",
                                    ""httpMethod"" : ""POST"",
                                    ""type"" : ""aws_proxy""
                                }}
                            }}
                        }}
                    }}
                }}");

        var restApiGateway = new RestApi("restAPI", new RestApiArgs
        {
            Body = body
        });

        var deployment = new Pulumi.Aws.ApiGateway.Deployment("dev-api", new DeploymentArgs
        {
            RestApi   = restApiGateway.Id,//strange it demands Id instead of Arn
            StageName = ""
        });

        var stage = new Stage("dev-api-stage", new StageArgs
        {
            RestApi    = restApiGateway.Id,
            Deployment = deployment.Id,
            StageName  = "test-stage",
        });

        var invokePermission = new Permission("api-lambda-permission", new PermissionArgs
        {
            Action    = "lambda:invokeFunction",
            Function  = lambda.Name,
            Principal = "apigateway.amazonaws.com",
            SourceArn = deployment.ExecutionArn.Apply(x => $"{x}*/*")
        });

        return(deployment.InvokeUrl.Apply(x => $"{x}test-stage"));
    }
Beispiel #3
0
 public MyStack()
 {
     var myapi = new Aws.ApiGateway.RestApi("myapi", new Aws.ApiGateway.RestApiArgs
     {
     });
     var dev = new Aws.ApiGateway.Deployment("dev", new Aws.ApiGateway.DeploymentArgs
     {
         RestApi   = myapi.Id,
         StageName = "dev",
     });
     var prod = new Aws.ApiGateway.Deployment("prod", new Aws.ApiGateway.DeploymentArgs
     {
         RestApi   = myapi.Id,
         StageName = "prod",
     });
     var myUsagePlan = new Aws.ApiGateway.UsagePlan("myUsagePlan", new Aws.ApiGateway.UsagePlanArgs
     {
         ApiStages =
         {
             new Aws.ApiGateway.Inputs.UsagePlanApiStageArgs
             {
                 ApiId = myapi.Id,
                 Stage = dev.StageName,
             },
             new Aws.ApiGateway.Inputs.UsagePlanApiStageArgs
             {
                 ApiId = myapi.Id,
                 Stage = prod.StageName,
             },
         },
         Description   = "my description",
         ProductCode   = "MYCODE",
         QuotaSettings = new Aws.ApiGateway.Inputs.UsagePlanQuotaSettingsArgs
         {
             Limit  = 20,
             Offset = 2,
             Period = "WEEK",
         },
         ThrottleSettings = new Aws.ApiGateway.Inputs.UsagePlanThrottleSettingsArgs
         {
             BurstLimit = 5,
             RateLimit  = 10,
         },
     });
 }
Beispiel #4
0
 public MyStack()
 {
     var myDemoAPI = new Aws.ApiGateway.RestApi("myDemoAPI", new Aws.ApiGateway.RestApiArgs
     {
         Description = "This is my API for demonstration purposes",
     });
     var myDemoResource = new Aws.ApiGateway.Resource("myDemoResource", new Aws.ApiGateway.ResourceArgs
     {
         RestApi  = myDemoAPI.Id,
         ParentId = myDemoAPI.RootResourceId,
         PathPart = "test",
     });
     var myDemoMethod = new Aws.ApiGateway.Method("myDemoMethod", new Aws.ApiGateway.MethodArgs
     {
         RestApi       = myDemoAPI.Id,
         ResourceId    = myDemoResource.Id,
         HttpMethod    = "GET",
         Authorization = "NONE",
     });
     var myDemoIntegration = new Aws.ApiGateway.Integration("myDemoIntegration", new Aws.ApiGateway.IntegrationArgs
     {
         RestApi    = myDemoAPI.Id,
         ResourceId = myDemoResource.Id,
         HttpMethod = myDemoMethod.HttpMethod,
         Type       = "MOCK",
     });
     var myDemoDeployment = new Aws.ApiGateway.Deployment("myDemoDeployment", new Aws.ApiGateway.DeploymentArgs
     {
         RestApi   = myDemoAPI.Id,
         StageName = "test",
         Variables =
         {
             { "answer", "42" },
         },
     }, new CustomResourceOptions
     {
         DependsOn =
         {
             myDemoIntegration,
         },
     });
 }