aws-servicediscovery: IHttpNamespace doesn't include createService
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
If you try to import any Cloud Map Namespaces using the `fromHttpNamespaceAttributes` method, you cannot call `createService` on the returned object because `IHttpNamespace` doesn't include it.
This is also true of `IPrivateDnsNamespace` and `IPublicDnsNamespace`.
### Expected Behavior
The following example should work:
```typescript
class ImportedNamespaceStack extends Stack {
constructor(scope: Construct, name: string, props: Props) {
const importedNamespace = HttpNamespace.fromHttpNamespaceAttributes(this, 'imported-namespace', {
namespaceName: 'imported',
namespaceId: 'ns-iwasimported',
namespaceArn: 'arn:aws:servicediscovery:us-east-1:123456789012:namespace/ns-iwasimported',
})
importedNamespace.createService('my-cool-service', { name: 'my-cool-service' })
}
}
```
### Current Behavior
It does not compile because `IHttpNamespace` has no method called `createService`.
### Reproduction Steps
See example in expected behavior
### Possible Solution
Expand the interface to include the method:
```typescript
export interface IHttpNamespace extends INamespace {
/**
* Creates a service within the namespace
*/
createService(id: string, props?: BaseServiceProps): Service
}
```
Modify the `fromHttpNamespaceAttributes` to return an object with it implemented:
```typescript
/**
* Creates a HTTP Namespace via all attributes.
*
* Note: While all attributes are required, only namespaceId is used (currently)
* by Service and so the other attributes may be set to placeholder values.
*/
public static fromHttpNamespaceAttributes(scope: Construct, id: string, attrs: HttpNamespaceAttributes): IHttpNamespace {
class Import extends Resource implements IHttpNamespace {
public namespaceName = attrs.namespaceName;
public namespaceId = attrs.namespaceId;
public namespaceArn = attrs.namespaceArn;
public type = NamespaceType.HTTP;
public createService(_id: string, props?: BaseServiceProps): Service {
return new Service(this, _id, {
namespace: this,
...props,
});
}
}
return new Import(scope, id);
}
```
### Additional Information/Context
_No response_
### CDK CLI Version
2.23.0 (build 50444aa)
### Framework Version
_No response_
### Node.js Version
v18.4.0
### OS
All
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start by locating the IHttpNamespace, IPrivateDnsNamespace, and IPublicDnsNamespace interfaces and their from...Attributes import entry points. Compare imported namespace behavior with regular namespace Service creation; done means all three imported namespace types expose createService and the provided TypeScript example compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100