I've concluded that Pulumi AI is not currently wor...
# pulumi-ai
n
I've concluded that Pulumi AI is not currently worth using as it consistently makes up interfaces/functions that don't exist. Perhaps those things might be useful as input for new feature development, but worse than useless for someone trying to work out how to use Pulumi to do something specific as I've wasted time trawling through docs only to find that the AI has told me to do things that aren't implemented.
w
Sorry to hear that @nice-sundown-31475. Any chance you can share examples of questions that made up APIs that weren’t supported? We are constantly working to improve accuracy, and working on tools to provide annotations on AI code examples we’ve confirmed do and don’t compile, to give additional confidence and signal on the outputs of the AI.
n
Not sure if I still have the examples, but I'm guessing that I can generate new ones 🙂
ok, with the prompt: generate a RESTful API using AWS API Gateway that supports CORS requests without generating the OPTIONS response in a lambda function
I got the following response:
To generate a RESTful API using AWS API Gateway that supports CORS requests without generating the OPTIONS response in a Lambda function, we can configure the API Gateway to handle CORS directly. This involves setting up the necessary resources and methods in API Gateway, and enabling CORS on the methods. Here's a Pulumi program to accomplish this:
Copy code
typescript
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an API Gateway REST API
const api = new aws.apigateway.RestApi("myApi", {
    description: "My REST API",
});

// Create a resource (e.g., /myresource)
const resource = new aws.apigateway.Resource("myResource", {
    parentId: api.rootResourceId,
    pathPart: "myresource",
    restApi: api.id,
});

// Create a GET method for the resource
const getMethod = new aws.apigateway.Method("getMethod", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: "GET",
    authorization: "NONE",
});

// Create a mock integration for the GET method
const getIntegration = new aws.apigateway.Integration("getIntegration", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: getMethod.httpMethod,
    type: "MOCK",
    requestTemplates: {
        "application/json": `{
            "statusCode": 200
        }`,
    },
    integrationResponses: [{
        statusCode: "200",
        responseTemplates: {
            "application/json": `{
                "message": "Hello, world!"
            }`,
        },
    }],
});

// Create a method response for the GET method
const getMethodResponse = new aws.apigateway.MethodResponse("getMethodResponse", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: getMethod.httpMethod,
    statusCode: "200",
    responseModels: {
        "application/json": "Empty",
    },
});

// Enable CORS for the GET method
const corsMethodResponse = new aws.apigateway.MethodResponse("corsMethodResponse", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: getMethod.httpMethod,
    statusCode: "200",
    responseParameters: {
        "method.response.header.Access-Control-Allow-Origin": true,
        "method.response.header.Access-Control-Allow-Headers": true,
        "method.response.header.Access-Control-Allow-Methods": true,
    },
});

const corsIntegrationResponse = new aws.apigateway.IntegrationResponse("corsIntegrationResponse", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: getMethod.httpMethod,
    statusCode: "200",
    responseParameters: {
        "method.response.header.Access-Control-Allow-Origin": "'*'",
        "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
        "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'",
    },
});

// Deploy the API
const deployment = new aws.apigateway.Deployment("deployment", {
    restApi: api.id,
    stageName: "prod",
}, { dependsOn: [getIntegration, corsIntegrationResponse] });

// Export the URL of the API
export const url = pulumi.interpolate`${deployment.invokeUrl}`;
This program sets up an API Gateway with a single resource and method, and configures CORS headers directly on the method responses. The
OPTIONS
method is not handled by a Lambda function but is instead managed by API Gateway's built-in capabilities.
but in the call:
Copy code
// Create a mock integration for the GET method
const getIntegration = new aws.apigateway.Integration("getIntegration", {
    restApi: api.id,
    resourceId: resource.id,
    httpMethod: getMethod.httpMethod,
    type: "MOCK",
    requestTemplates: {
        "application/json": `{
            "statusCode": 200
        }`,
    },
    integrationResponses: [{
        statusCode: "200",
        responseTemplates: {
            "application/json": `{
                "message": "Hello, world!"
            }`,
        },
    }],
});
integrationResponses
is not a valid property of the
IntegrationArgs
object.
VSCode highlights the problem since it's typescript, but it still takes time to check the package definitions.
f
I actively avoid the Pulumi AI search results for this reason. I actually reported hallucinations in this channel here https://pulumi-community.slack.com/archives/C055KGGFB1N/p1700781644040989 and also to our solutions engineer contact at Pulumi. I got a notification about Pulumi Copilot today and I will give it a try but I will be approaching it with scepticism. I did find an open issue similar to what I was trying to solve https://github.com/pulumi/pulumi-kubernetes/issues/1260