I'm having trouble finding any message on this is the documentation. I know that this line is the problem line, because when I comment it out, "cdk deploy" works just fine. Basically, I am getting a url as a parameter from the user (I am aware parameters are not recommended by AWS, but this is necessary for my use case). I then use that parameter to subscribe to an SNS topic in the following line:
my_sns_topic.add_subscription(subscriptions.UrlSubscription(pagerduty_url.value_as_string))
When this line isn't commented out, I get the following error:
jsii.errors.JSIIError: Must provide protocol if url is unresolved
I can subscribe something using an email protocol to this SNS topic just fine, so I don't think it's the SNS topic itself. It works when I just directly pass the URL as a string into the function as well, so it seems to be an issue with the parameter. So, how do I fix this? I understand it wants to have an alternative in case the url is not valid, but there's no information in the CDK documentation on how to actually do this, either that or I'm just not finding it.
Because you are using a CfnParameter and the value can't be read at synth time then the UrlSubscription class has no way of inferring the protocol used, so you must provide it yourself. Take a look here for reference:
https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_sns_subscriptions/UrlSubscription.html
Try:
my_sns_topic.add_subscription(subscriptions.UrlSubscription(pagerduty_url.value_as_string, protocol=sns.SubscriptionProtocol.HTTPS))
If it isn't always going to be an HTTPS protocol then that'll likely have to be another Parameter you request from the user.
Related
I would greatly benefit from a list of all the available headers that App Service can forward to my (keyword PYTHON) Function. Or if someone knows how to "list-all", that would be awesome.
Through asking questions on SO, I see that the request IP addressed can be gleaned using:
req.headers.get("X-FORWARDED-FOR").
I need the Hostname that a request is coming from.
Looks like this is possible using C# Functions. But I either did it wrong using req.headers.Host or its not available for Python.
Is it possible using Python?
For this requirement, you just need to use req.headers.get("host"). I test it in my side, it works fine on azure portal.
Hello I am interested in one thing.I know it can be silly question but I can not understand one thing here:
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LocationConstraint>eu-central-1</LocationConstraint>
</CreateBucketConfiguration>
is "http://s3.amazonaws.com/doc/2006-03-01/" URL or URI?
cause when I type it in browser it shows me this:
screenshot
It's both. A uniform resource identifier (URI) provides a name for a resource. A URL (uniform resource locator) is a kind of URI that describes where (and how) the resource can be accessed.
The URL you provide, http://s3.amazonaws.com/doc/2006-03-01/, doesn't tell you anything about what is there. It simply says that if you use the HTTP protocol to connect to s3.amazonaws.com and request /doc/2006-03-01/, you'll get something back. What that something is is only implied by the name of the XML attribute that has the URL as its value.
(In practice, the server may not actually provide a resource at that location, but it could. The error message you see indicates there might be something there, but you don't have permission to access it.)
I'm trying to test batch enrollment for build up the google classroom, but I found some compile error at batch.execute(http=**http**)
error message is "Undefinded variable: http"
this is the code and compile error occurred the last part of this code.
def callback(request_id, response, exception):
if exception is not None:
print('Error adding user "{0}" to the course course: {1}'.format(
request_id, exception))
else:
print('User "{0}" added as a student to the course.'.format(
response.get('profile').get('name').get('fullName')))
batch = service.new_batch_http_request(callback=callback)
for student_email in student_emails:
student = {
'userId': student_email
}
request = service.courses().students().create(courseId=course_id,
body=student)
batch.add(request, request_id=student_email)
batch.execute(http=http)
and the reference is below that.
https://developers.google.com/classroom/guides/batch#python
Somebody help me.
Let's dig into the documentation to find the answer!
The error appears on a call to the execute function of the batch object. So what kind of an object is batch?
It was returned from a call to the new_batch_http_request of the service object. So what kind of an object is service?
It's not created in the reference code you cited, so we have to rummage around in the document to find some other code where something named service is created. The authors probably assumed that service in this example is the same kind of object.
The Quickstart page for Python seems like a good place to look and sure enough, there is code that creates an object named service there:
service = build('classroom', 'v1', credentials=creds)
So we can guess that service was returned from a call to build. So what is build?
It's defined in that same sample:
from googleapiclient.discovery import build
So now we have to find the documentation for googleapiclient.discovery. A search for that name leads us to:
https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.discovery-module.html
Here we see that the build function returns a Resource. So service is a Resource.
But when we look at the documentation for Resource, it has no function new_batch_http_request. What foul treachery is this?
"new_batch_http_request" looks like a pretty distinctive string, so we can search for that. Let's try the search box of the Google Classroom API site.
It only finds the Batching Requests page where we started. But it also offers to search all of Google Developers. So let's do that.
The search results then show that there are a lot of APIs with functions with this name and they all seem to create BatchHttpRequest objects, so the one for Resource probably does, too. So what is a BatchHttpRequest? Let's do another search for this name!
It turns out to be documented as part of the http module of the googleapiclient package at
https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.http.BatchHttpRequest-class.html
The error came from a call to the execute function of the batch object, which we have guessed to be a BatchHttpRequest. Fortunately, a BatchHttpRequest has an execute function and that execute function takes an http argument. The documentation of the execute function says that the http argument can be omitted, but if it is supplied, it should be an httplib2.Http.
The reference code passes an object called http as the parameter also called http, but doesn't bother to construct it. That's why the compiler is complaining that it's undefined.
So to get the code to compile, you should be able just to omit the http=http parameter. Then maybe it will run and maybe it won't. If it doesn't, you will have to figure out how to construct an appropriate Http object using the httplib2 library, with documentation at:
https://httplib2.readthedocs.io/en/latest/libhttplib2.html#http-objects
I am trying to send a API query for Subnet Creation. Please note that the authentication code is working the problem is just with the parameter string:
request_parameters = 'Action=CreateSubnet&**VpcId=vpc-1738886c**&CidrBlock=20.20.3.0%2F28&Version=2016-11-15'
When I send this, I get: AWS was not able to validate the provided access credentials
For the exact same code, when I send:
"request_parameters = 'Action=CreateVpc&CidrBlock=20.20.3.0%2F24&Version=2016-11-15'" # It works!!
I am guessing there is something wrong with: VpcId=vpc-1738886c
Being same user, I am able to create a subnet in that VPC with same CIDR block in the console so permission doesn't seem to be an issue.
Please can you advise? Thanks in advance.
"AWS was not able to validate the provided access credentials" should mean you have an issue in the signing code -- not in the actual parameters.
Initially, it's hard to see why that might be the case, here... but it is.
The problem lies in the fact that you need to be signing the canonical representation of the query string... which means the parameters must be sorted lexically when signing:
# canonical representation
Action=CreateSubnet&CidrBlock=20.20.3.0%2F28&Version=2016-11-15&VpcId=vpc-1738886c
There can be no safe assumptions about the order in which a query string's parameters may change end-to-end on the Internet, so the AWS signing algorithms require them to be sorted for signing. The order in the actual HTTP request doesn't matter, but the order when signing does.
First of all, my question is similar to this one
But it's a little bit different.
What we have is a series of environments, with the same set of services.
For some environments (the local ones) we can get access to the wsdl, and thus generating the suds client.
For external environment, we cannot access the wsdl. But being the same, I was hoping I can change just the URL without regenerating the client.
I've tried cloning the client, but it doesn't work.
Edit: adding code:
host='http://.../MyService.svc'
wsdl_file = 'file://..../wsdl/MyService.wsdl'
client = suds.client.Client(wsdl_file, location=host, cache=None)
#client = baseclient.clone()
#client.options.location = otherhost
client.set_options(port='BasicHttpBinding_IMyService')
result = client.service.IsHealthy()
That gives me this exception:
The message with Action 'http://tempuri.org/IMyService/IsHealthy' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
The thing is, if I set the client directly to the host, it works fine:
client = suds.client.Client(host)
As you can see, I've tried cloning the client, but with the same exception. I even tried this:
baseclient = suds.client.Client(host)
client = baseclient.clone()
client.options.location = otherhost
....
And got the same exception.
Anyone can help me?
client.sd[0].service.setlocation(new_url)
...is the "manual" way, ie. per service-description.
client.set_option(new_url)
...should also work, per the author.
options is a wrapped/protected attr -- direct edits may very well be ignored.
I've got it!.
I don't even know how I've figured it out, but with a little of guessing and a much of luck I ended up with this:
wsdl_file = 'file://...../MyService.wsdl'
client = suds.client.Client(wsdl_file)
client.wsdl.url = host #this line did the trick
client.set_options(port='BasicHttpBinding_IMyService')
result = client.service.IsHealthy()
And it works!
I can't find any documentation about that property (client.wsdl.url), but it works, so I post it in case someone have the same problem.
You might be able to do that by specifying the location of the service. Assuming you have a Client object called client, you can modify the service location by updating the URL in client.options.location.
Additionally you are able to use a local copy of a WSDL file as the url when constructing the client by using a file:// scheme for the URL, e.g. file:///path/to/service.wsdl. So this could be another option for you. Of course you would also have to specify the location so that the default location from within the WSDL is overridden.